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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 361D6C43334 for ; Thu, 30 Jun 2022 01:15:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E64B8E0001; Wed, 29 Jun 2022 21:15:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9960E6B0073; Wed, 29 Jun 2022 21:15:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80F808E0001; Wed, 29 Jun 2022 21:15:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6B91E6B0072 for ; Wed, 29 Jun 2022 21:15:07 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 44C24792 for ; Thu, 30 Jun 2022 01:15:07 +0000 (UTC) X-FDA: 79633133454.19.0055CD9 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf15.hostedemail.com (Postfix) with ESMTP id D4F12A002F for ; Thu, 30 Jun 2022 01:15:06 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id c4so15639427plc.8 for ; Wed, 29 Jun 2022 18:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=frAHI2bOMbVWhVrFm/iD28e4xSqa2fepuAWtZya7n6o=; b=AQOYbRtS2ApmyDE/gr+1XfUFQkEICrqDu1aX37NxuJF3jKX2r/r6nOTZZorPx/zJoN 8PxSwGgBwr2483zF9Yh64DyIQnXrLOFgJRrwW1ujAVuA5mmdCgiLsQ/9IEr/dGnnf6PQ PiyVLUSu9TrNlVIk7eknJWdz8dyDSqCwvLKnF9vPhJKjLttGiwDJVrUSEzqmmCH9Uccs bCdme1Rwp3LwcrYX3QFmvfSnVeqzxkl4yHbzjTpQVoCXGXgO3uufuirC3Jkm2D9NJbIA 9v8zurofvldNF2DBySqHpL9GgQHXBrTck/H31GhGEPHEAOxaQ56hjhhK/CBEtW3V7eCk 7yNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=frAHI2bOMbVWhVrFm/iD28e4xSqa2fepuAWtZya7n6o=; b=gWHG2GpmopXivGy1+vaM/4b0ML+I6SxMEbnCv0vt327ljY/eybdzuDvc5L+roQyEhE wDZD/Nog78lbRuQKD4T6WJGTIHa18VqjX0SUmDzNJIt5zHeu2KbkzF7z6/riRzXM3/KN HEZusn+jGJwlPldKjaAJYlY5/pasvA2z5P0S6vK2QlX0h5ykuIDY3kEmgAvDTSTwAPpT x6ssaFYnfIOMnZlDqAg/bNH9G3ngl9eIPrFTRm+ICnlFebtUlMc2ckJfrJDeARf9XzxE R+kkVvGulLEL1gpDvEtJ9UgMVN/Va8Bngtbimz3HnTkE/qaHEJH1TkEqg5WSzMlyByyN XcPw== X-Gm-Message-State: AJIora9uJoiQnnbmmcCHjgozkzY2jk5wy9N/CsIDTTEfLF3e8UnjcSX3 SbFBnRYll4jeRfT9TdOX+9g++A== X-Google-Smtp-Source: AGRyM1vckr+Q/Prq1pHxAsCfcTpm+gpxnkvS9xbF/8RM+07zqGufDVJAeyLUY/6bdlYjss9enyBo+Q== X-Received: by 2002:a17:90b:1a88:b0:1ed:5a12:514b with SMTP id ng8-20020a17090b1a8800b001ed5a12514bmr9183791pjb.49.1656551705587; Wed, 29 Jun 2022 18:15:05 -0700 (PDT) Received: from google.com (55.212.185.35.bc.googleusercontent.com. [35.185.212.55]) by smtp.gmail.com with ESMTPSA id c20-20020a17090aa61400b001ec84049064sm2848527pjq.41.2022.06.29.18.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 18:15:05 -0700 (PDT) Date: Wed, 29 Jun 2022 18:15:01 -0700 From: Zach O'Keefe To: Peter Xu Cc: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Rongwei Wang , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org, Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer Subject: Re: [PATCH v6 01/15] mm: khugepaged: don't carry huge page to the next loop for !CONFIG_NUMA Message-ID: References: <20220604004004.954674-1-zokeefe@google.com> <20220604004004.954674-2-zokeefe@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656551706; a=rsa-sha256; cv=none; b=o8up8j8Ws+5U+Rj2kSdEiBOWSybQq0l200NdlvWe2AOP4wlat+KS0LVbAGNa3fMV7ooN8B lpMtvjIZ+6Txh9zfwn62C/uTxnKnN3OmGzRGzxcSyfoSaCQJXfeEa+/LnfWxkgLS9dsd9n Mwy8Uo4++YRoFvxU6vqglGY44BTUHDc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AQOYbRtS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of zokeefe@google.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zokeefe@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656551706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=frAHI2bOMbVWhVrFm/iD28e4xSqa2fepuAWtZya7n6o=; b=Vye9VZCV/COv+C7iaglby6OVNCVxYYsRsntnk8gRm/da8qtfC0/L1Sib67ONYevaZroJ8h XbUe3FzxXBTfobW48Qb7QgEHKx+r9HKpKFunqSZiF/BX38wiJNEcXNC2H93z/7Ea/naBES VtOpbdgowq1tSHSeN8l6qoOhysdLEOA= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AQOYbRtS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of zokeefe@google.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D4F12A002F X-Stat-Signature: 38b47iiqwjzhk6uppfpte37sjup1ayrq X-Rspam-User: X-HE-Tag: 1656551706-150763 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 Jun 29 16:49, Peter Xu wrote: > On Fri, Jun 03, 2022 at 05:39:50PM -0700, Zach O'Keefe wrote: > > -static bool khugepaged_prealloc_page(struct page **hpage, bool *wait) > > +/* Sleep for the first alloc fail, break the loop for the second fail */ > > +static bool alloc_fail_should_sleep(struct page **hpage, bool *wait) > > { > > if (IS_ERR(*hpage)) { > > if (!*wait) > > - return false; > > + return true; > > > > *wait = false; > > *hpage = NULL; > > khugepaged_alloc_sleep(); > > - } else if (*hpage) { > > - put_page(*hpage); > > - *hpage = NULL; > > } > > - > > - return true; > > + return false; > > } > > One nitpick here: > > It's weird to me to sleep in a function called XXX_should_sleep(), we'd > normally expect to sleep only if it returns true. > > Meanwhile, would this be a very good chance to unwrap this function already > to remove the "bool*" reference, which looks not pretty? Something like: > > ---8<--- > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 16be62d493cd..807c10cd0816 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2235,9 +2235,6 @@ static void khugepaged_do_scan(void) > lru_add_drain_all(); > > while (progress < pages) { > - if (!khugepaged_prealloc_page(&hpage, &wait)) > - break; > - > cond_resched(); > > if (unlikely(kthread_should_stop() || try_to_freeze())) > @@ -2253,6 +2250,18 @@ static void khugepaged_do_scan(void) > else > progress = pages; > spin_unlock(&khugepaged_mm_lock); > + > + if (IS_ERR(*hpage)) { > + /* > + * If fail to allocate the first time, try to sleep > + * for a while. When hit again, cancel the scan. > + */ > + if (!wait) > + break; > + wait = false; > + *hpage = NULL; > + khugepaged_alloc_sleep(); > + } > } > ---8<--- > > Would this look slightly better? Hey Peter, Thanks for taking the time to review. I think open coding this looks good. One small detail is that if we move this to the end of the loop, we'll need to check that progress < pages still before sleeping - else we run the risk of doing an alloc sleep and a scan sleep. But I'll let Yang make the call since it's his patch - he's just been kind enough to donate it for this cause :) Thanks, Zach > Thanks, > > -- > Peter Xu >