From patchwork Mon Nov 26 23:33:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 10699375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7243A13BB for ; Mon, 26 Nov 2018 23:33:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6232D2A63F for ; Mon, 26 Nov 2018 23:33:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54DB82A646; Mon, 26 Nov 2018 23:33:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA6912A63F for ; Mon, 26 Nov 2018 23:33:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00E766B4475; Mon, 26 Nov 2018 18:33:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F00656B4476; Mon, 26 Nov 2018 18:33:17 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5FD6B4477; Mon, 26 Nov 2018 18:33:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 961956B4475 for ; Mon, 26 Nov 2018 18:33:17 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id w19-v6so22295595plq.1 for ; Mon, 26 Nov 2018 15:33:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :in-reply-to:message-id:references:user-agent:mime-version; bh=Gn5WzFahKDFmpa30/2NDbGP8DwU+8tgzl9BF6DVEeRU=; b=WaK4KcakbbVTAMPJU7kIYUXwmeOSVNS9d/o52wwmYcBYGOKIEFZ1wM7D4mFV1LoLlG Wh4aoshAkZ9Uv7vLTNPbL8OlF95UaLfAy1e9JbyIgFGWhMX12c4XhLVqZ1I6Dy2g5c7n 5Jbz9Zc/xaM8N2fxoSKdW2Si792l+4j3+PEwWiKBr/zyoSf2VCjd+qYeQA2iCNhEn/sC a9ibWaYTxSOO78WSfiarqAn8fBtgJv3c5DN4aoBzAsLPIg6VxnrYYsxN1Z/zh8GHFj3x BgYQ2MG2pxji0erDclqjR/73SDXIzXC4KoJPliRoBEHGrQu6AYlMllhBSANunTaQQOxy 3ubQ== X-Gm-Message-State: AA+aEWZBG/nHlzSXqoV5f50Tl4GdKMrheTn9SHl49DIC/pYdL6iIJMRw KiaAmf+JKWOd8JXlLWcEcjOcN2B1/g+P5lvftLzY/aaw0XhGC4ShRI2MlKQ64kBTEehAr2JD676 fBHfumjZakitOjJaxRFu8ZMKp+Xuu54zlZAUxwoKu+r3ICN46j0QZ4FkahDhWuZBSS8tOOAxQFt jTnL3E37LWMNkHHEIUSs6O7+yRCxiWebw+o70P1uBuUzNG4VuO8NW2rrzaFbavkl+zAjKijgpwc fAJD39eYJfwJv5i267zGcXjFThyVYziJGVQSEyS699HE4N/bDTaN8nz6pi1yoytAVFItmMq0BGC 5ypXr2RFlfyDZ8lxbzJVT7fn5RIHxomM/5Q8M2hCD9m7GwdYVcrtSKtdHi6/GEp+TmLlJ5FJ+/e q X-Received: by 2002:a63:d604:: with SMTP id q4mr26688641pgg.175.1543275197271; Mon, 26 Nov 2018 15:33:17 -0800 (PST) X-Received: by 2002:a63:d604:: with SMTP id q4mr26688607pgg.175.1543275196581; Mon, 26 Nov 2018 15:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543275196; cv=none; d=google.com; s=arc-20160816; b=jlKQoESfLKJ9y+cPM2bYXEchvF8ZMo6cywUTxvwaEmPPGgvXfB8CoGx6NYjx2IsC+F 6Y7CRjL9kSVxqKSOt6iIYZGvDSfecciiUbSKZq0Pf9vjxLVIjy/vblaHMxPhJRfxEsKd HpK2dCXsTiCjGtjSajh6ZrsOD3vb+sROh6jH0xilt5Ay3VDdV1xADGGZbX/n1H8MlZtP 3yH2PEu8hqVPGh6ATrQJhd9t9hNe/g+O6vCok8dwClS0V4GVOmsT5loK0wBo1/YLp4xc TjOq3FZHBPIhNrNcxzqeT961qGboZCr886l0xZgFOzNANuYZkbPo++txmvckGro2fzjH ySpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature; bh=Gn5WzFahKDFmpa30/2NDbGP8DwU+8tgzl9BF6DVEeRU=; b=rCfn6jBYNIbupRaGz8yx46q7QrK+VDX5qajES5LtcPJYEyj5+GOEMEjlc32yBk/lP9 OFZuaoMHqj3a0zhZ2B0L0koav7uZIEZI3p/938a0RgrQWKq86K4+05Aykbp3ZHjNF4F2 KlVs74TsFs15tHdtFNHofkHs/tANgeQB6TMOaiwMwnyIMfb7XwpiZw7jRa245STreJds v4QlMRhyt0+mw3YtfVmQ5GgfL7j3cUWtVJvO0+jKRKTYj6TsIEkLaFi1C9qHWHKsnN5H r9mpoF/Bu2xpU11HNzjHAK8Wa8UklztyUTPNbJUlGYuWs4KdrtrRqqIdzqd6WJXJf8dS xnOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d7JkLxnu; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c84sor2876236pfe.49.2018.11.26.15.33.16 for (Google Transport Security); Mon, 26 Nov 2018 15:33:16 -0800 (PST) Received-SPF: pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d7JkLxnu; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=Gn5WzFahKDFmpa30/2NDbGP8DwU+8tgzl9BF6DVEeRU=; b=d7JkLxnu9k7CIQwnZzNVNTqJYebgfKTts683dxF7n4UvUqyJDHcsKIxUoZrLbF4j0i n6BcXscIHeA8NncV15JObW0fJlFOyNekTbDZZ5bgyI+0B7kqFy1vVEoa/yatfyfg9RwZ SnHYLmyjLWG5NkTotJWEPRCJDF9vhJ1V1+WSofeoBdv0V8uLUgJwtykkkNEsSy4jfq5W iCRpFK83CMSdjwxVyWcXFteVarvtk1nrQikQddte6BsWLs+8m52p4lL1xj4eJsqYvvJ5 6nd/p+Oo6d9joT1+Rf9BPYMIzxEW6Wv9RgsEsCE8WwRqMgCFUEQqk5E0aMiESCvun4EJ RhtA== X-Google-Smtp-Source: AJdET5f50/WgEk/RfZl8C0LYOZc+o7YOeYAz9JSfv2TN/XIGb5Extn+Zl6CFyrTa6P+OsN4nPcFGug== X-Received: by 2002:a62:9111:: with SMTP id l17mr30171177pfe.200.1543275195826; Mon, 26 Nov 2018 15:33:15 -0800 (PST) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id c13sm2028740pfo.121.2018.11.26.15.33.14 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 15:33:15 -0800 (PST) Date: Mon, 26 Nov 2018 15:33:13 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , "Kirill A. Shutemov" , Matthew Wilcox , linux-mm@kvack.org Subject: [PATCH 10/10] mm/khugepaged: fix the xas_create_range() error path In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP collapse_shmem()'s xas_nomem() is very unlikely to fail, but it is rightly given a failure path, so move the whole xas_create_range() block up before __SetPageLocked(new_page): so that it does not need to remember to unlock_page(new_page). Add the missing mem_cgroup_cancel_charge(), and set (currently unused) result to SCAN_FAIL rather than SCAN_SUCCEED. Fixes: 77da9389b9d5 ("mm: Convert collapse_shmem to XArray") Signed-off-by: Hugh Dickins Cc: Matthew Wilcox Cc: Kirill A. Shutemov Acked-by: Kirill A. Shutemov --- mm/khugepaged.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 2c5fe4f7a0c6..8e2ff195ecb3 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1329,6 +1329,20 @@ static void collapse_shmem(struct mm_struct *mm, goto out; } + /* This will be less messy when we use multi-index entries */ + do { + xas_lock_irq(&xas); + xas_create_range(&xas); + if (!xas_error(&xas)) + break; + xas_unlock_irq(&xas); + if (!xas_nomem(&xas, GFP_KERNEL)) { + mem_cgroup_cancel_charge(new_page, memcg, true); + result = SCAN_FAIL; + goto out; + } + } while (1); + __SetPageLocked(new_page); __SetPageSwapBacked(new_page); new_page->index = start; @@ -1340,17 +1354,6 @@ static void collapse_shmem(struct mm_struct *mm, * be able to map it or use it in another way until we unlock it. */ - /* This will be less messy when we use multi-index entries */ - do { - xas_lock_irq(&xas); - xas_create_range(&xas); - if (!xas_error(&xas)) - break; - xas_unlock_irq(&xas); - if (!xas_nomem(&xas, GFP_KERNEL)) - goto out; - } while (1); - xas_set(&xas, start); for (index = start; index < end; index++) { struct page *page = xas_next(&xas);