All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin LaHaise <ben@communityfibre.ca>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>, Tejun Heo <tj@kernel.org>,
	axboe@kernel.dk, viro@zeniv.linux.org.uk,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-aio@kvack.org
Subject: Re: [PATCH 0/5] blkcg: Limit maximum number of aio requests available for cgroup
Date: Tue, 5 Dec 2017 10:35:03 -0500	[thread overview]
Message-ID: <20171205153503.GE15720@kvack.org> (raw)
In-Reply-To: <20171205151956.GA22836@redhat.com>

On Tue, Dec 05, 2017 at 04:19:56PM +0100, Oleg Nesterov wrote:
> On 12/05, Kirill Tkhai wrote:
> >
> > Currently, aio_nr and aio_max_nr are global.
> 
> Yeah, I too tried to complain 2 years ago...
> 
> > In case of containers this
> > means that a single container may occupy all aio requests, which are
> > available in the system,
> 
> and memory. let me quote my old emails...
> 
> 
> This is off-topic, but the whole "vm" logic in aio_setup_ring()
> looks sub-optimal. I do not mean the code, just it seems to me it
> is pointless to pollute the page cache, and expose the pages we
> can not swap/free to lru. Afaics we _only_ need this for migration.

It is needed for migration, which is needed for hot unplug of memory.
There is no way around this.

> This memory lives in page-cache/lru, it is visible for shrinker which
> will unmap these pages for no reason on memory shortage. IOW, aio fools
> the kernel, this memory looks reclaimable but it is not. And we only do
> this for migration.

It's the same as any other memory that's mlock()ed into RAM.

> Even if this is not a problem, this does not look right. So perhaps at
> least mapping_set_unevictable() makes sense. But I simply do not know
> if migration will work with this change.
> 
> 
> 
> Perhaps I missed something, doesn't matter. But this means that
> this memory is not accounted, so if I increase aio-max-nr then
> this test-case
> 
> 	#define __NR_io_setup	206
> 
> 	int main(void)
> 	{
> 		int nr;
> 
> 		for (nr = 0; ;++nr) {
> 			void *ctx = NULL;
> 			int ret = syscall(__NR_io_setup, 1, &ctx);
> 			if (ret) {
> 				printf("failed %d %m: ", nr);
> 				getchar();
> 			}
> 		}
> 
> 		return 0;
> 	}
> 
> triggers OOM-killer which kills sshd and other daemons on my machine.
> These pages were not even faulted in (or the shrinker can unmap them),
> the kernel can not know who should be blamed.

The OOM-killer killed the wrong process: News at 11.  This is not new
behaviour, and has always been an issue.  If it bothered to kill the
process that was doing the allocations, the ioctxes would be freed and all
would be well.  Doesn't the OOM killer take into account which process is
allocating memory?  Seems like a pretty major deficiency if it isn't.

> Shouldn't we account aio events/pages somehow, say per-user, or in
> mm->pinned_vm ?

Sure, I have no objection to that.  Please send a patch!

> I do not think this is unkown, and probably this all is fine. IOW,
> this is just a question, not a bug-report or something like this.
> 
> And of course, this is not exploitable because aio-max-nr limits
> the number of pages you can steal.

Which is why the aio-max-nr limit exists!  That it is imprecise and
imperfect is not being denied.

> But otoh, aio_max_nr is system-wide, so the unpriviliged user can
> ddos (say) mysqld. And this leads to the same question: shouldn't
> we account nr_events at least?

Anyone can DDoS the local system - this nothing new and has always been
the case.  I'm not opposed to improvements in this area.  The only issue I
have with Kirill's changes is that we need to have test cases for this new
functionality if the code is to be merged.

TBH, using memory accounting to limit things may be a better approach, as
that at least doesn't require changes to containers implementations to
obtain a benefit from bounding aio's memory usage.

		-ben

> Oleg.
> 

-- 
"Thought is the essence of where you are now."

  reply	other threads:[~2017-12-05 15:35 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 16:12 [PATCH 0/5] blkcg: Limit maximum number of aio requests available for cgroup Kirill Tkhai
2017-12-04 16:12 ` Kirill Tkhai
2017-12-04 16:12 ` [PATCH 1/5] aio: Move aio_nr increment to separate function Kirill Tkhai
2017-12-04 16:13 ` [PATCH 2/5] aio: Export aio_nr_lock and aio_max_nr initial value to include/linux/aio.h Kirill Tkhai
2017-12-04 16:13 ` [PATCH 3/5] blkcg: Add blkcg::blkg_aio_nr and blkcg::blkg_aio_max_nr Kirill Tkhai
2017-12-04 16:13 ` [PATCH 4/5] blkcg: Charge aio requests in blkio cgroup hierarchy Kirill Tkhai
2017-12-04 16:13 ` [PATCH 5/5] blkcg: Add cgroup file to configure blkcg::blkg_aio_max_nr Kirill Tkhai
2017-12-04 16:52 ` [PATCH 0/5] blkcg: Limit maximum number of aio requests available for cgroup Benjamin LaHaise
2017-12-04 21:27   ` Kirill Tkhai
2017-12-04 21:35     ` Jeff Moyer
2017-12-04 21:35       ` Jeff Moyer
2017-12-04 21:48       ` Kirill Tkhai
2017-12-04 20:07 ` Tejun Heo
2017-12-04 21:44   ` Kirill Tkhai
2017-12-04 21:52     ` Tejun Heo
2017-12-04 22:49       ` Kirill Tkhai
2017-12-04 22:59         ` Jeff Moyer
2017-12-04 22:59           ` Jeff Moyer
2017-12-04 23:14           ` Kirill Tkhai
2017-12-05 15:41             ` Jeff Moyer
2017-12-05 15:41               ` Jeff Moyer
2017-12-05 15:51               ` Tejun Heo
2017-12-04 23:02         ` Tejun Heo
2017-12-04 23:05           ` Kirill Tkhai
2017-12-05 15:19     ` Oleg Nesterov
2017-12-05 15:35       ` Benjamin LaHaise [this message]
2017-12-06 17:32         ` Oleg Nesterov
2017-12-06 17:44           ` Benjamin LaHaise
2017-12-06 17:44             ` Benjamin LaHaise
2017-12-06 18:19             ` Kirill Tkhai
2017-12-06 18:30               ` Benjamin LaHaise
2017-12-06 19:37                 ` Kirill Tkhai
2017-12-07 13:44             ` Oleg Nesterov

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

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

  git send-email \
    --in-reply-to=20171205153503.GE15720@kvack.org \
    --to=ben@communityfibre.ca \
    --cc=axboe@kernel.dk \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.