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 B56D3C43334 for ; Wed, 15 Jun 2022 15:14:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ACE36B0071; Wed, 15 Jun 2022 11:14:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25C716B0074; Wed, 15 Jun 2022 11:14:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1241E6B0078; Wed, 15 Jun 2022 11:14:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 047BB6B0071 for ; Wed, 15 Jun 2022 11:14:41 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C755F20CF8 for ; Wed, 15 Jun 2022 15:14:40 +0000 (UTC) X-FDA: 79580817120.24.F34E1EC Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf05.hostedemail.com (Postfix) with ESMTP id 74669100098 for ; Wed, 15 Jun 2022 15:14:38 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id cx11so11534349pjb.1 for ; Wed, 15 Jun 2022 08:14:38 -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=1qhKddPqonN/zP/GiDkOrtFuHIgE7zljctNwI9S4zyY=; b=Z+B7AoLqPAPphaZAEaeSdA8hjKnZpgaxJYTjYPC5x2GwU1vPoYtDnzr1Cy22VQtVpB GS+uzvDFiCSy/zXXTSQU2Ss60c3Qsaa1XJfoNXrXw9uTdznIDB8NXmjDy/S3fPR3iirw Wo9KPIGYpg1dxcDUqkvxoYJGXty29kmT3l6Bjg+vll+tOhL4w2cCibJ4cK93P3fofMF/ O76/kYxE3R7OVvo+HVbkis37t821Kpa1znqsUwyM2OR6OAO6MwE1gNUhZdss24IDslTY yHX85OGBVsFiNkMjBzi0MUP1KF98jhCsH4ChDMCe8D1LCRY+PMfgC7yEs/qbZ33Y6p4X JCVw== 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=1qhKddPqonN/zP/GiDkOrtFuHIgE7zljctNwI9S4zyY=; b=OxbxvZKpM9q0AVA7cMVhljeuhwSy7r1VvO/yG37BFmUW7xjq+dz40SCB9GdD512hCR sSH031hHcMOzJpTuyFa2li4QZqjjVQgVi3gtSQgwFFLwKEVaSJ8NJOOLV9LgdQV44aHq Z/BgkOetyhbxz3jBLs7uGyAYqA290VM0xjtB/jO3v0N7NjoGhw5eVvmKO5JhZa5/SJyh SL1T91QZg7V0qdY1opJ5FwCdQmrgDfnwdGwJ4BttO7YHiHdfLoai+hKmc4cKMOytr9tp k3lobAv/XuvGb9EQ2mNsgMtEEUQQ1RNAS6ZgCf3yRusPIj1amuoWqmcQIrnbKq7t10rR Oikw== X-Gm-Message-State: AJIora85UV8TekbxiFYDH8UW/xJA3cmHqdEdK5uipJtsHzXWuOqkj/Ah 8H2wLXdQQjykBsqKv3/y5oDdFxsTq2WFPn5u X-Google-Smtp-Source: AGRyM1uxHj6R4sbIxf0Zg4t5IclxLq6pAQSzx2aBq8UNHAow2bgLm6NcTqYoXR6ttPc2ANrhu4bvEA== X-Received: by 2002:a17:90b:38c8:b0:1e8:5202:f6d4 with SMTP id nn8-20020a17090b38c800b001e85202f6d4mr3272pjb.149.1655306076948; Wed, 15 Jun 2022 08:14:36 -0700 (PDT) Received: from google.com (55.212.185.35.bc.googleusercontent.com. [35.185.212.55]) by smtp.gmail.com with ESMTPSA id d13-20020a170902654d00b001637704269fsm9468817pln.223.2022.06.15.08.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 08:14:36 -0700 (PDT) Date: Wed, 15 Jun 2022 08:14:32 -0700 From: Zach O'Keefe To: Miaohe Lin Cc: akpm@linux-foundation.org, aarcange@redhat.com, willy@infradead.org, vbabka@suse.cz, dhowells@redhat.com, neilb@suse.de, apopple@nvidia.com, david@redhat.com, surenb@google.com, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] mm/khugepaged: stop swapping in page when VM_FAULT_RETRY occurs Message-ID: References: <20220611084731.55155-1-linmiaohe@huawei.com> <20220611084731.55155-3-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220611084731.55155-3-linmiaohe@huawei.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655306078; a=rsa-sha256; cv=none; b=xVhjtK80K67cu3UdIWLNXsEZu0E2a/YltIHO//pegBxjs+KNa6t5p+mfT//q4qY7+UOJbJ xgZ77cLIN0Kr0k81mg5ivaL42Eqk1zrfNM1sXANk3bLcZtqAmrgTBBHySAkE53uzCpkZ1a rY//mGXIIfRFzAoQzXbtCbh3NLmw+Ik= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z+B7AoLq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of zokeefe@google.com designates 209.85.216.49 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=1655306078; 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=1qhKddPqonN/zP/GiDkOrtFuHIgE7zljctNwI9S4zyY=; b=T6Lu1+4Oe6tzCiamIqr0BguRLqo4vEyJmeMakElw9Ow2atx7hdLEiJ/7B2dw6CKzkoL9i2 zIUBs9hubVEI9DDgqnbLgis7y7bW0sYTn4aGFtzvCTbkjT8HvRuZw0kXYvvXF+Q9ftwvoJ u5/VQwdcgDRLxZLJBky5yDlW8H2iZc0= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 74669100098 X-Stat-Signature: 43n36tb5s5mutp3sjq5fjtq457cwk1fx Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z+B7AoLq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of zokeefe@google.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Rspam-User: X-HE-Tag: 1655306078-483678 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 11 Jun 16:47, Miaohe Lin wrote: > When do_swap_page returns VM_FAULT_RETRY, we do not retry here and thus > swap entry will remain in pagetable. This will result in later failure. > So stop swapping in pages in this case to save cpu cycles. > > Signed-off-by: Miaohe Lin > --- > mm/khugepaged.c | 19 ++++++++----------- > 1 file changed, 8 insertions(+), 11 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 73570dfffcec..a8adb2d1e9c6 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -1003,19 +1003,16 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm, > swapped_in++; > ret = do_swap_page(&vmf); > > - /* do_swap_page returns VM_FAULT_RETRY with released mmap_lock */ > + /* > + * do_swap_page returns VM_FAULT_RETRY with released mmap_lock. > + * Note we treat VM_FAULT_RETRY as VM_FAULT_ERROR here because > + * we do not retry here and swap entry will remain in pagetable > + * resulting in later failure. > + */ > if (ret & VM_FAULT_RETRY) { > mmap_read_lock(mm); > - if (hugepage_vma_revalidate(mm, haddr, &vma)) { > - /* vma is no longer available, don't continue to swapin */ > - trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, 0); > - return false; > - } > - /* check if the pmd is still valid */ > - if (mm_find_pmd(mm, haddr) != pmd) { > - trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, 0); > - return false; > - } > + trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, 0); > + return false; > } > if (ret & VM_FAULT_ERROR) { > trace_mm_collapse_huge_page_swapin(mm, swapped_in, referenced, 0); > -- > 2.23.0 > > I've convinced myself this is correct, but don't understand how we got here. AFAICT, we've always continued to fault in pages, and, as you mention, don't retry ones that have failed with VM_FAULT_RETRY - so __collapse_huge_page_isolate() should fail. I don't think (?) there is any benefit to continuing to swap if we don't handle VM_FAULT_RETRY appropriately. So, I think this change looks good from that perspective. I suppose the only other question would be: should we handle the VM_FAULT_RETRY case? Maybe 1 additional attempt then fail? AFAIK, this mostly (?) happens when the page is locked. Maybe it's not worth the extra complexity though..