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 E3261C433EF for ; Wed, 29 Jun 2022 20:49:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C6768E0001; Wed, 29 Jun 2022 16:49:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 476AC6B0072; Wed, 29 Jun 2022 16:49:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 316A08E0001; Wed, 29 Jun 2022 16:49:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1FBCC6B0071 for ; Wed, 29 Jun 2022 16:49:33 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id EAA6A8093B for ; Wed, 29 Jun 2022 20:49:32 +0000 (UTC) X-FDA: 79632464184.08.E8B858C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 6CE0FC002E for ; Wed, 29 Jun 2022 20:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656535771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lv5CtOjzVVpQeQDfWeClyJ2a87IFuFdtg0AdIRSKJf4=; b=TdK5mp7UplsOosEmZ6/U4F+iZCTmuK1ZU0wN48/hDXExi2I0ThXH5mIeo0fLf9r1tCBwHU ng4jNVS1EQdRwMfX4sPVxMpQfn1BY4/cI6wdIOTE5OWNjo0aV685oLYVfO45JH9VCEv5Yq GKkghaCzGuWSpSu+bU3qslziENX1HC0= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-281-8fjB8vomPx2TEMx83a_Riw-1; Wed, 29 Jun 2022 16:49:26 -0400 X-MC-Unique: 8fjB8vomPx2TEMx83a_Riw-1 Received: by mail-io1-f70.google.com with SMTP id x2-20020a6bda02000000b0067590503c08so902543iob.5 for ; Wed, 29 Jun 2022 13:49:26 -0700 (PDT) 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=Lv5CtOjzVVpQeQDfWeClyJ2a87IFuFdtg0AdIRSKJf4=; b=3xy8aCtHy1lppnjZEONRTYmlBdX4KZ/GL4VRl1Pgwyj55fw3+3OqMNlUvQG5KLNEpb AF569l95VyT1trZcGK/VQ7UdO0AjYL7lL+NgU90Stl+XnsvSowxOF3eedajwA3Ae+YUd M3v/Za16vPVhlMyaoEisZ301Iq1RLW8PRR05pbeat5NBl03cgh6TpJ4tOXNGZUpw1R0i vSMr2vN5LPuJ0Pnj0tL7SpaxSyAB/2qwkiXey/UfuiPEiT57Cm0f7JpsYGMkRCYQ3tNF 0zLOKD3k7nWyBjyxJWROzFfcA43OcmC7u1tpC8A6eIHABT+SJlbIS9C/4TuJ4BRS2bNy 3JTw== X-Gm-Message-State: AJIora9XfE1AMfCER7Hc7XYb1Kk5inLA4iVdinjmWky6oeBQo+QkZ1ev n3OS/YO9yHQvOLKDwUkyOw4/lnb/ycamD3syp5r/pkWQrBRO04pbxhOpW+ZwRtbNUTRh/Sr0MPw JzdeZQnU0sHQ= X-Received: by 2002:a02:a78c:0:b0:339:ed30:1a3e with SMTP id e12-20020a02a78c000000b00339ed301a3emr3107528jaj.0.1656535765386; Wed, 29 Jun 2022 13:49:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sD6oh6vGdUu+xKBCz/icQSx5TDBulC0Mb1QAwfbpI4tnfWZihz+MWQLua5iC9sjKoexMmIjQ== X-Received: by 2002:a02:a78c:0:b0:339:ed30:1a3e with SMTP id e12-20020a02a78c000000b00339ed301a3emr3107496jaj.0.1656535765013; Wed, 29 Jun 2022 13:49:25 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id bo8-20020a056638438800b0033171dafaa0sm7640015jab.178.2022.06.29.13.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 13:49:24 -0700 (PDT) Date: Wed, 29 Jun 2022 16:49:20 -0400 From: Peter Xu To: Zach O'Keefe 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 In-Reply-To: <20220604004004.954674-2-zokeefe@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdK5mp7U; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656535772; a=rsa-sha256; cv=none; b=mKiBMnUIPPsPB0PaDzZqS5Hh9Ay/eLt9rxXMrjUodhH7BZ1nNKyShScgvvN0AxcH4UP1Ti 8XpfGm72LxVpT2LJqETxzkfR/Tq4U7MisTtLoKkqfKUogEDMvoNoMhmASIWvrmSwzoyeVm 5d4u/N0Q93UxSqqYKq1FClzpnsmTSAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656535772; 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=Lv5CtOjzVVpQeQDfWeClyJ2a87IFuFdtg0AdIRSKJf4=; b=Z3im1eLkPPfHIIzquz9ol5PoKXsb6Fe0kzpOyADx1nk6iYZVdSFlMruXRkhkan8SGOAm9w O2enlM9PRn8fFWIc8wbKzRZaiVZ/659Y+HkscB5Y7H/jbpL/NcnQpUJ4vG74bvM690uCNg 4GwIkFIVqjkc5ebkF0e8NmK2TJtMY/M= X-Stat-Signature: 51gtujohiuqqzoi3a7w1h74djqm4sgz4 X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 6CE0FC002E Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdK5mp7U; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1656535772-113659 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 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? Thanks, -- Peter Xu