From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A61FCC433DF for ; Thu, 25 Jun 2020 12:31:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 769EE20709 for ; Thu, 25 Jun 2020 12:31:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 769EE20709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E7C056B0074; Thu, 25 Jun 2020 08:31:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E060E6B0075; Thu, 25 Jun 2020 08:31:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCC9B6B0078; Thu, 25 Jun 2020 08:31:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id B033E6B0074 for ; Thu, 25 Jun 2020 08:31:47 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 116FD8245571 for ; Thu, 25 Jun 2020 12:31:47 +0000 (UTC) X-FDA: 76967670654.23.bear29_35032cd26e4c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id C612737610 for ; Thu, 25 Jun 2020 12:31:46 +0000 (UTC) X-HE-Tag: bear29_35032cd26e4c X-Filterd-Recvd-Size: 5765 Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Thu, 25 Jun 2020 12:31:46 +0000 (UTC) Received: by mail-ej1-f67.google.com with SMTP id w16so5770698ejj.5 for ; Thu, 25 Jun 2020 05:31:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LfL/J6kcjTPEsDskt6aLX8PefsDeHP4anavcHPUMTKA=; b=eGGPm+X6tQzCphan/bF3iRhTAujkMP0QZsPYhKcq6j6n/xlPohdGz7p+MU6EG5wApd JyMuaTHNvgXJ6Q+43IF0JwgB51ESqWf8t7hKI6zW7SAyp5H44VziiHTA/VvAvguh6/tK Cs9k0FcAo9rRfBtzjUo9o7QQ9Mp6ARFusGwexVgaHBAS2poOquAOQTY0uy8dk1imyZWL 0faIkG498IZV0/n33YJHx8VIspr+kZTHJ0Zwug34mBg8N+x6YHJ+nmYJ/Zp95jH73HtO TZ/FM27PF9+GgrNHD1iw2gXKN/MkR2lf43X7nC8Z0kvbPDZZwYLqqY5qkoPRl6CA1SH4 2XiQ== X-Gm-Message-State: AOAM533JnrCzoQ3XGMP1FVfFmW20rYBImp8wmZ2uZ3YHZfIGYojmKzep TewWk2vKtY8m+vdwr0XWj7o= X-Google-Smtp-Source: ABdhPJyiXDwgXlrcNxDquN/m7X009TUFeb5rEVdNCJL2oLKPwCGm2N5mD6JL7UM8/mFBSoWnOD0BJw== X-Received: by 2002:a17:906:3d41:: with SMTP id q1mr30164872ejf.12.1593088305149; Thu, 25 Jun 2020 05:31:45 -0700 (PDT) Received: from localhost (ip-37-188-168-3.eurotel.cz. [37.188.168.3]) by smtp.gmail.com with ESMTPSA id u13sm11449983ejx.3.2020.06.25.05.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 05:31:44 -0700 (PDT) Date: Thu, 25 Jun 2020 14:31:43 +0200 From: Michal Hocko To: "Matthew Wilcox (Oracle)" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@redhat.com, Mikulas Patocka , Jens Axboe , NeilBrown Subject: Re: [PATCH 2/6] mm: Add become_kswapd and restore_kswapd Message-ID: <20200625123143.GK1320@dhcp22.suse.cz> References: <20200625113122.7540-1-willy@infradead.org> <20200625113122.7540-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625113122.7540-3-willy@infradead.org> X-Rspamd-Queue-Id: C612737610 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 25-06-20 12:31:18, Matthew Wilcox wrote: > Since XFS needs to pretend to be kswapd in some of its worker threads, > create methods to save & restore kswapd state. Don't bother restoring > kswapd state in kswapd -- the only time we reach this code is when we're > exiting and the task_struct is about to be destroyed anyway. > > Signed-off-by: Matthew Wilcox (Oracle) Certainly better than an opencoded PF_$FOO manipulation Acked-by: Michal Hocko I would just ask for a clarification because this is rellying to have a good MM knowledge to follow > +/* > + * Tell the memory management that we're a "memory allocator", I would go with. Tell the memory management that the caller is working on behalf of the background memory reclaim (aka kswapd) and help it to make a forward progress. That means that it will get an access to memory reserves should there be a need to allocate memory in order to make a forward progress. Note that the caller has to be extremely careful when doing that. Or something like that. > + * and that if we need more memory we should get access to it > + * regardless (see "__alloc_pages()"). "kswapd" should > + * never get caught in the normal page freeing logic. > + * > + * (Kswapd normally doesn't need memory anyway, but sometimes > + * you need a small amount of memory in order to be able to > + * page out something else, and this flag essentially protects > + * us from recursively trying to free more memory as we're > + * trying to free the first piece of memory in the first place). > + */ > +#define KSWAPD_PF_FLAGS (PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD) > + > +static inline unsigned long become_kswapd(void) > +{ > + unsigned long flags = current->flags & KSWAPD_PF_FLAGS; > + current->flags |= KSWAPD_PF_FLAGS; > + return flags; > +} > + > +static inline void restore_kswapd(unsigned long flags) > +{ > + current->flags &= ~(flags ^ KSWAPD_PF_FLAGS); > +} > + > static inline void set_current_io_flusher(void) > { > current->flags |= PF_LOCAL_THROTTLE; > diff --git a/mm/vmscan.c b/mm/vmscan.c > index b6d84326bdf2..27ae76699899 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3870,19 +3870,7 @@ static int kswapd(void *p) > if (!cpumask_empty(cpumask)) > set_cpus_allowed_ptr(tsk, cpumask); > > - /* > - * Tell the memory management that we're a "memory allocator", > - * and that if we need more memory we should get access to it > - * regardless (see "__alloc_pages()"). "kswapd" should > - * never get caught in the normal page freeing logic. > - * > - * (Kswapd normally doesn't need memory anyway, but sometimes > - * you need a small amount of memory in order to be able to > - * page out something else, and this flag essentially protects > - * us from recursively trying to free more memory as we're > - * trying to free the first piece of memory in the first place). > - */ > - tsk->flags |= PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD; > + become_kswapd(); > set_freezable(); > > WRITE_ONCE(pgdat->kswapd_order, 0); > @@ -3932,8 +3920,6 @@ static int kswapd(void *p) > goto kswapd_try_sleep; > } > > - tsk->flags &= ~(PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD); > - > return 0; > } > > -- > 2.27.0 > -- Michal Hocko SUSE Labs