sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH 6/6] avoid ENOMEM checking in common code paths
Date: Thu, 11 Apr 2013 04:17:35 +0000	[thread overview]
Message-ID: <1365653855-1101-7-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1365653855-1101-1-git-send-email-normalperson@yhbt.net

ENOMEM from syscalls such as inotify_add_watch and epoll_ctl are
from the lack of kernel memory, so even a successful rb_gc() is
unlikely to be able to reap memory taken from those slab caches.
---
 ext/sleepy_penguin/epoll.c   | 10 ++--------
 ext/sleepy_penguin/inotify.c | 11 +++--------
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c
index 70a77f6..179fe06 100644
--- a/ext/sleepy_penguin/epoll.c
+++ b/ext/sleepy_penguin/epoll.c
@@ -134,14 +134,8 @@ static VALUE epctl(VALUE self, VALUE _op, VALUE io, VALUE events)
 	pack_event_data(&event, io);
 
 	rv = epoll_ctl(epfd, op, fd, &event);
-	if (rv < 0) {
-		if (errno == ENOMEM) {
-			rb_gc();
-			rv = epoll_ctl(epfd, op, fd, &event);
-		}
-		if (rv < 0)
-			rb_sys_fail("epoll_ctl");
-	}
+	if (rv < 0)
+		rb_sys_fail("epoll_ctl");
 
 	return Qnil;
 }
diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c
index f858dc4..4c606a4 100644
--- a/ext/sleepy_penguin/inotify.c
+++ b/ext/sleepy_penguin/inotify.c
@@ -89,14 +89,9 @@ static VALUE add_watch(VALUE self, VALUE path, VALUE vmask)
 	uint32_t mask = rb_sp_get_uflags(self, vmask);
 	int rc = inotify_add_watch(fd, pathname, mask);
 
-	if (rc == -1) {
-		if (errno == ENOMEM) {
-			rb_gc();
-			rc = inotify_add_watch(fd, pathname, mask);
-		}
-		if (rc == -1)
-			rb_sys_fail("inotify_add_watch");
-	}
+	if (rc == -1)
+		rb_sys_fail("inotify_add_watch");
+
 	return UINT2NUM((uint32_t)rc);
 }
 
-- 
1.8.2.279.g631bc94



      parent reply	other threads:[~2013-04-11  4:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11  4:17 [sleepy.penguin] [PATCH 0/6] epoll wrapper cleanups Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 1/6] test_epoll: fix timing error in test Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 2/6] test_epoll: synchronize writes to the pipe array Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 3/6] split Epoll and Epoll::IO, rewrite Epoll in Ruby Eric Wong
2013-04-12 20:38   ` Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 4/6] epoll: implement thread-safety for mark/flag arrays Eric Wong
2013-04-12 21:18   ` Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 5/6] epoll: cache alignment for per-thread structure Eric Wong
2013-04-11  4:17 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/sleepy_penguin/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365653855-1101-7-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy.penguin@librelist.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).