From patchwork Mon Jan 9 13:42:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9504801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9385D606E1 for ; Mon, 9 Jan 2017 13:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87025284D0 for ; Mon, 9 Jan 2017 13:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79A4D284D5; Mon, 9 Jan 2017 13:52:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 287E8284D0 for ; Mon, 9 Jan 2017 13:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751162AbdAINnF (ORCPT ); Mon, 9 Jan 2017 08:43:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:48379 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933371AbdAINmQ (ORCPT ); Mon, 9 Jan 2017 08:42:16 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2608FAC02; Mon, 9 Jan 2017 13:42:13 +0000 (UTC) Date: Mon, 9 Jan 2017 14:42:10 +0100 From: Michal Hocko To: Vlastimil Babka Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Dave Chinner , djwong@kernel.org, Theodore Ts'o , Chris Mason , David Sterba , Jan Kara , ceph-devel@vger.kernel.org, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, logfs@logfs.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mtd@lists.infradead.org, reiserfs-devel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-f2fs-devel@lists.sourceforge.net, linux-afs@lists.infradead.org, LKML Subject: Re: [PATCH 3/8] mm: introduce memalloc_nofs_{save,restore} API Message-ID: <20170109134210.GI7495@dhcp22.suse.cz> References: <20170106141107.23953-1-mhocko@kernel.org> <20170106141107.23953-4-mhocko@kernel.org> <86dbce74-a532-2f98-6a63-4dbad77b2aa1@suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <86dbce74-a532-2f98-6a63-4dbad77b2aa1@suse.cz> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon 09-01-17 14:04:21, Vlastimil Babka wrote: [...] > > +static inline unsigned int memalloc_nofs_save(void) > > +{ > > + unsigned int flags = current->flags & PF_MEMALLOC_NOFS; > > + current->flags |= PF_MEMALLOC_NOFS; > > So this is not new, as same goes for memalloc_noio_save, but I've > noticed that e.g. exit_signal() does tsk->flags |= PF_EXITING; > So is it possible that there's a r-m-w hazard here? exit_signals operates on current and all task_struct::flags should be used only on the current. [...] > > @@ -3029,7 +3029,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, > > int nid; > > struct scan_control sc = { > > .nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX), > > - .gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | > > + .gfp_mask = (current_gfp_context(gfp_mask) & GFP_RECLAIM_MASK) | > > So this function didn't do memalloc_noio_flags() before? Is it a bug > that should be fixed separately or at least mentioned? Because that > looks like a functional change... We didn't need it. Kmem charges are opt-in and current all of them support GFP_IO. The LRU pages are not charged in NOIO context either. We need it now because there will be callers to charge GFP_KERNEL while being inside the NOFS scope. Now that you have opened this I have noticed that the code is wrong here because GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK would overwrite the removed GFP_FS. I guess it would be better and less error prone to move the current_gfp_context part into the direct reclaim entry - do_try_to_free_pages - and put the comment like this Acked-by: Vlastimil Babka diff --git a/mm/vmscan.c b/mm/vmscan.c index 4ea6b610f20e..df7975185f11 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2756,6 +2756,13 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist, int initial_priority = sc->priority; unsigned long total_scanned = 0; unsigned long writeback_threshold; + + /* + * Make sure that the gfp context properly handles scope gfp mask. + * This might weaken the reclaim context (e.g. make it GFP_NOFS or + * GFP_NOIO). + */ + sc->gfp_mask = current_gfp_context(sc->gfp_mask); retry: delayacct_freepages_start(); @@ -2949,7 +2956,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, unsigned long nr_reclaimed; struct scan_control sc = { .nr_to_reclaim = SWAP_CLUSTER_MAX, - .gfp_mask = (gfp_mask = current_gfp_context(gfp_mask)), + .gfp_mask = gfp_mask, .reclaim_idx = gfp_zone(gfp_mask), .order = order, .nodemask = nodemask, @@ -3029,8 +3036,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, int nid; struct scan_control sc = { .nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX), - .gfp_mask = (current_gfp_context(gfp_mask) & GFP_RECLAIM_MASK) | - (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK), + .gfp_mask = GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK, .reclaim_idx = MAX_NR_ZONES - 1, .target_mem_cgroup = memcg, .priority = DEF_PRIORITY, @@ -3723,7 +3729,7 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in int classzone_idx = gfp_zone(gfp_mask); struct scan_control sc = { .nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX), - .gfp_mask = (gfp_mask = current_gfp_context(gfp_mask)), + .gfp_mask = gfp_mask, .order = order, .priority = NODE_RECLAIM_PRIORITY, .may_writepage = !!(node_reclaim_mode & RECLAIM_WRITE),