Message ID | 20231119194740.94101-20-ryncsn@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1810247vqn; Sun, 19 Nov 2023 11:50:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2urK0MFxuqY6kP50ily29RYtB2LdTx0KXuSgJc77T2sy5IWIzrqHbKa/tr5AWegZvqdG0 X-Received: by 2002:a17:902:ec8f:b0:1cc:54fb:60f9 with SMTP id x15-20020a170902ec8f00b001cc54fb60f9mr7054269plg.37.1700423440210; Sun, 19 Nov 2023 11:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700423440; cv=none; d=google.com; s=arc-20160816; b=NxJF5sesMVsSvIK9O6FIRl5B7uKkGIrKZcIEFooXRjOTgs4EWaBh4mVTT5bBnI/VR2 z4VRQv50QRDW9M/KjUZuNhnUUinS98MpKf9DAxjgNsrLm5EfqBn9vNcGIs+efrOWotxL Y49v3bcA28Pi1tqvgrfOSOhwQ/Lb4LWfKSk8da5/zHIrDeHNam3jK+wlvSNBOS4Zecef 32rslR8ZqQKY6cvy5MaW2meWFOCWLeo7hJbGaapSV9A3rusR9w889g/eIGV40+mCosao SRxghFbMxA1ud1S31G7zzt6KL9DDE8MBFlH2/oLulHD63dGG+YCbPvYp5pGR//p9ceHR Tmpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; fh=4HE/piJoUCKuBTCCBiej4//zvvzywHdOLL9QM/KYjYM=; b=mBppBNjSJR6mEU8r8kjPlSGF3LZaRY+nSl3Q/x/CYA6iHzeB8rWCUBGah6fZu4B17p x6HFJmxLYRAooBGWSbkq5C1KE0uYTpy+fhwT/Ok8eKTQwCNwTq4EF69wcb3dQ/DO4V8p YcKStkF+xRTJc0gb2A3YR2ZIo16Q+srG6K4BAJ3Hgah+FM77xWkklO5Q06oTqv4ga4Xj +NJIxYEGqwMWvDdh5AkEFrFO3SGhZDQNZHdefZxHgmAtbiUx/2RFnFFho0K08NjxM8PU PPH3O1rdlyOXQFlN/eu1W0vmyssL2u8Pb3WbKxsp3Y+u0nGI+2eI6lJOAZ0ikwf9i981 1Xig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Afvt9npR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j8-20020a170902690800b001c9e890f42bsi6535131plk.78.2023.11.19.11.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 11:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Afvt9npR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D98FD80C1139; Sun, 19 Nov 2023 11:50:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231795AbjKSTuU (ORCPT <rfc822;jaysivo@gmail.com> + 29 others); Sun, 19 Nov 2023 14:50:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbjKSTtv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 19 Nov 2023 14:49:51 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DA91BD9 for <linux-kernel@vger.kernel.org>; Sun, 19 Nov 2023 11:49:03 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b1d1099a84so3606091b3a.1 for <linux-kernel@vger.kernel.org>; Sun, 19 Nov 2023 11:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423343; x=1701028143; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; b=Afvt9npRwp95Im/FJLQ4+yLe4XtjOwRQlS5Bcenqfiu6s4zOVDNDC9TnLd2LDWhRkG Lf2Rk1xnJAxJCu05N3e5x7+kA52CyzE4QJvMnOej7jgkD7/TrKSYRxbeOZEiENa+1ffx vaITqRi5dxBNDB6InBBqOjlYYUHzoHuLXQxS3uUm9Mm/TnDtbYFej+7QIU3OEdCuKRKS UQG2QXnrODblRWZXfWxIhATw7KrBUVCu+krtYU7WYC5sGIqFPI8CE/QBuZK7Otg+aMeK w5ww+J45bGxSYsmDtMx2bO7Ot7hUiqUc+FTLPFYeQUCZv/sjEXwEGjoAB6Y3u1k5xelF gCQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423343; x=1701028143; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; b=hcr1MX/sniu/lkyTjcNc2ScEKn2CY5CQTz1Ha4oLyM/fySwiB1asq7RWacA4ri1yGq yYWiMt2khDWNXvL7kHkj4a4XQhxLEHFfG3UPhnyEPOw+V5WWmrdv/+TfOI1ABPkIHtjA G4TRwR/O1l6oV1wkAjPvhA9s2gIi539cbYqPDmacaUcRNp3yzLHRSidzj0rl7W6IE5Cl Ik1IsK3XR7L1IJSuNqBsfKqhA9TCX70A05aYe12ZvzQ19bW0gLbWB19K6x4RzwH1RURD dMfR6Gk3wi2LFpJClvYimhmK/8VCpvt/CE/JuCl//8SJgZdmMl8C2wkfK/BGA9CLojbl mhtw== X-Gm-Message-State: AOJu0YxMWPGOpR9DEg3WP4XUy3GEhnANX0smxKd1gSjuHkt7Mdc9XQ/G nu7Rxnjvxm3tbMyUpkjapR4= X-Received: by 2002:a05:6a20:748e:b0:186:58d6:ca65 with SMTP id p14-20020a056a20748e00b0018658d6ca65mr7241893pzd.32.1700423343119; Sun, 19 Nov 2023 11:49:03 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.49.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:49:02 -0800 (PST) From: Kairui Song <ryncsn@gmail.com> To: linux-mm@kvack.org Cc: Andrew Morton <akpm@linux-foundation.org>, "Huang, Ying" <ying.huang@intel.com>, David Hildenbrand <david@redhat.com>, Hugh Dickins <hughd@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Matthew Wilcox <willy@infradead.org>, Michal Hocko <mhocko@suse.com>, linux-kernel@vger.kernel.org, Kairui Song <kasong@tencent.com> Subject: [PATCH 19/24] shmem, swap: refactor error check on OOM or race Date: Mon, 20 Nov 2023 03:47:35 +0800 Message-ID: <20231119194740.94101-20-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song <kasong@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 11:50:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783023209009242930 X-GMAIL-MSGID: 1783023209009242930 |
Series |
Swapin path refactor for optimization and bugfix
|
|
Commit Message
Kairui Song
Nov. 19, 2023, 7:47 p.m. UTC
From: Kairui Song <kasong@tencent.com> It should always check if a swap entry is already swaped in on error, fix potential false error issue. Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/shmem.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Comments
Hi Kairui, On Sun, Nov 19, 2023 at 11:49 AM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > It should always check if a swap entry is already swaped in on error, > fix potential false error issue. > > Signed-off-by: Kairui Song <kasong@tencent.com> > --- > mm/shmem.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 81d129aa66d1..6154b5b68b8f 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1857,13 +1857,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, > page = swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, &result); > mpol_cond_put(mpol); > > - if (PTR_ERR(page) == -EBUSY) { > - if (!shmem_confirm_swap(mapping, index, swap)) > - return -EEXIST; Do you intentionally remove checking shmem_confirm_swap()? I am not sure I am following. > + if (IS_ERR_OR_NULL(page)) { > + if (!page) > + error = -ENOMEM; > else > - return -EINVAL; > - } else if (!page) { > - error = -ENOMEM; > + error = -EINVAL; The resulting code is a bit hard to read in diff. In plan source it is like: if (IS_ERR_OR_NULL(page)) { if (!page) error = -ENOMEM; else error = -EINVAL; goto failed; } else { folio = page_folio(page); if (fault_type && result != SWAP_CACHE_HIT) { *fault_type |= VM_FAULT_MAJOR; count_vm_event(PGMAJFAULT); count_memcg_event_mm(fault_mm, PGMAJFAULT); } } First of all, if the first always "goto failed", the second else is not needed. The whole else block can be flatten one indentation. if (IS_ERR_OR_NULL(page)) { if (!page) error = -ENOMEM; else error = -EINVAL; goto failed; } else { Can be rewrite as following with less indentation: if (!page) { error = -ENOMEM; goto failed; } if (IS_ERR(page)) { error = -EINVAL; goto failed; } /* else block */ Am I missing something and misreading your code? Chris
Chris Li <chrisl@kernel.org> 于2023年11月20日周一 15:12写道: > > Hi Kairui, > > On Sun, Nov 19, 2023 at 11:49 AM Kairui Song <ryncsn@gmail.com> wrote: > > > > From: Kairui Song <kasong@tencent.com> > > > > It should always check if a swap entry is already swaped in on error, > > fix potential false error issue. > > > > Signed-off-by: Kairui Song <kasong@tencent.com> > > --- > > mm/shmem.c | 10 ++++------ > > 1 file changed, 4 insertions(+), 6 deletions(-) > > > > diff --git a/mm/shmem.c b/mm/shmem.c > > index 81d129aa66d1..6154b5b68b8f 100644 > > --- a/mm/shmem.c > > +++ b/mm/shmem.c > > @@ -1857,13 +1857,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, > > page = swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, &result); > > mpol_cond_put(mpol); > > > > - if (PTR_ERR(page) == -EBUSY) { > > - if (!shmem_confirm_swap(mapping, index, swap)) > > - return -EEXIST; > > Do you intentionally remove checking shmem_confirm_swap()? > I am not sure I am following. Hi, Chris, thanks for the review. This was also called under failed: label so I think there is no need to keep it here. > > > + if (IS_ERR_OR_NULL(page)) { > > + if (!page) > > + error = -ENOMEM; > > else > > - return -EINVAL; > > - } else if (!page) { > > - error = -ENOMEM; > > + error = -EINVAL; > > The resulting code is a bit hard to read in diff. In plan source it is like: > > if (IS_ERR_OR_NULL(page)) { > if (!page) > error = -ENOMEM; > else > error = -EINVAL; > goto failed; > } else { > folio = page_folio(page); > if (fault_type && result != SWAP_CACHE_HIT) { > *fault_type |= VM_FAULT_MAJOR; > count_vm_event(PGMAJFAULT); > count_memcg_event_mm(fault_mm, PGMAJFAULT); > } > } > > First of all, if the first always "goto failed", the second else is not needed. > The whole else block can be flatten one indentation. Yes, thanks for the suggestion. > > if (IS_ERR_OR_NULL(page)) { > if (!page) > error = -ENOMEM; > else > error = -EINVAL; > goto failed; > } else { > > Can be rewrite as following with less indentation: > > if (!page) { > error = -ENOMEM; > goto failed; > } > if (IS_ERR(page)) { > error = -EINVAL; > goto failed; > } > /* else block */ > > Am I missing something and misreading your code? Your code looks cleaner :) This patch is trying to clean up the error path after the helper refactor, and your suggestions are very helpful, thanks! > > Chris
diff --git a/mm/shmem.c b/mm/shmem.c index 81d129aa66d1..6154b5b68b8f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1857,13 +1857,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, page = swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, &result); mpol_cond_put(mpol); - if (PTR_ERR(page) == -EBUSY) { - if (!shmem_confirm_swap(mapping, index, swap)) - return -EEXIST; + if (IS_ERR_OR_NULL(page)) { + if (!page) + error = -ENOMEM; else - return -EINVAL; - } else if (!page) { - error = -ENOMEM; + error = -EINVAL; goto failed; } else { folio = page_folio(page);