From patchwork Wed Jan 25 01:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13114947 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 DAAA4C54E94 for ; Wed, 25 Jan 2023 01:58:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E50C96B0071; Tue, 24 Jan 2023 20:58:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E02A86B0072; Tue, 24 Jan 2023 20:58:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC8246B0073; Tue, 24 Jan 2023 20:58:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BD7D16B0071 for ; Tue, 24 Jan 2023 20:58:15 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9105AA0A62 for ; Wed, 25 Jan 2023 01:58:15 +0000 (UTC) X-FDA: 80391661350.29.6ECCDD8 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf19.hostedemail.com (Postfix) with ESMTP id D13001A0006 for ; Wed, 25 Jan 2023 01:58:12 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WAqnNhti; spf=pass (imf19.hostedemail.com: domain of 3s4zQYwcKCDQpeaUUVUWeeWbU.SecbYdkn-ccalQSa.ehW@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3s4zQYwcKCDQpeaUUVUWeeWbU.SecbYdkn-ccalQSa.ehW@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674611892; 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: references:dkim-signature; bh=fp9ccs/R/HqGAoRU6R/FJYwx892zglssKTnZXb6TNhs=; b=d0lkoYMa6Pb0wiW+dKDGmJKsCa19M7NmQrzOmtoMgGjFuN3yF2n17xIiRKI7/HusTEREW3 oOLmq3waFreRL6Kr2Rr2rEhKvNRctM95Mw6pQC8UTv2Cj+RaMG60l/ft6Md0CZrxNI2QvO buNGukmMmV5FUDsxWMo4CeY1QV6GULw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WAqnNhti; spf=pass (imf19.hostedemail.com: domain of 3s4zQYwcKCDQpeaUUVUWeeWbU.SecbYdkn-ccalQSa.ehW@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3s4zQYwcKCDQpeaUUVUWeeWbU.SecbYdkn-ccalQSa.ehW@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674611892; a=rsa-sha256; cv=none; b=DgDo4t8snZcjRsaheRePL3jqNoz5Ff2L0Sn/1LhsLK7btfff5tAZjngpMCfR544afwNiBq u3Ap/STgTE8XlcQM8796YkctAwsxyHd/STyjDSuxPK6JZfYa+TTOzZ9AYRrJS7CoEfe8nH /MjHLI/a6y+5FIFFljvkbGVXfoCMP2o= Received: by mail-pg1-f201.google.com with SMTP id a33-20020a630b61000000b00429d91cc649so7576150pgl.8 for ; Tue, 24 Jan 2023 17:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=fp9ccs/R/HqGAoRU6R/FJYwx892zglssKTnZXb6TNhs=; b=WAqnNhtiG8WjUY8O+bk3uMlpTRdXAO1398g06DJIjO5tpLENLCDEFEWfl5MKQQ2cS4 FJmL4Hx1MgPkUvaWuxuEKoXfRmKWL2q9d5N75BjvVzLdMDt/6/LMiboSf2ZuostsQRoT 5oOPTgTiEDS0FKff/+yrSTTKn/j66fTfrr+Er9d8jkJiPj/NjiPkpckv7Sfa8Z4H5BlN +qW9JTz3wAKujy3DdbdwCaEfka7lpLk/bYQvXMvMgNfLHIjIFV2LvQDDSZdYttuhSOO5 tVfxl+1M1BxCZvN4M8o48BWAxGGoiHGmTA+PLRW0WNl344BBT0PzlqW+jQqTi6sTu+My HpVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fp9ccs/R/HqGAoRU6R/FJYwx892zglssKTnZXb6TNhs=; b=slK9NLBE0SaKIwXG4Ke/6J0OYSrKsM3wYw9HvFFQALP9agJ3rXSbPrZJxOV9C+V725 dQFySbRx8vT7EA1dwklvZSj5A+ogzEEhE4Er9TTrcAFwMgiNN0faEta8Ba5HgSazfWFz sPAO6WGQmBNkCiYucJEUOY9tmey+4+FwVJpZjJdFk46w2nlwaHXDWVdsWwU64e+7k4vP Xal9vameBywGQ3FBuCKlIiWYH8Unwp9FWXlGu+YIsgUYcktT5bC0yYSm8rDsf0Wwy2Ko 3IjrqyrvUEvD9q050SnEvvpoJspHcZuxGcE8uRZkshS2IO/3VBRzWTzp6plQhwg1oBXJ njRA== X-Gm-Message-State: AFqh2koYABfGiljASBS8IgWNlVfqf+6uqwfftRTHYYcED54mrJDGOD5D 0DHhkK4eILU7UZKFajQWAbQAEwhNweZ6x5ekHjTkjEEjea7yXGrhBKPxQce1pS2kvX86MWiaFor OGtryzaejnaku4HZAB2sN0BAigHyBLXbnzeUI0LZVj3nws9mAXqKtxNXiJSQ= X-Google-Smtp-Source: AMrXdXumtB1amnGJ3IJUGIww8hnAuAjaZabzfhDhTWmrwPx4x/+DFmvmnBwEW8RCk35Au2yhMVxS0rtyDwrR X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:22ca:b0:58b:3d7f:746a with SMTP id f10-20020a056a0022ca00b0058b3d7f746amr3665212pfj.77.1674611891064; Tue, 24 Jan 2023 17:58:11 -0800 (PST) Date: Tue, 24 Jan 2023 17:57:37 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog Message-ID: <20230125015738.912924-1-zokeefe@google.com> Subject: [PATCH 1/2] mm/MADV_COLLAPSE: set EAGAIN on unexpected page refcount From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Yang Shi , "Zach O'Keefe" X-Rspamd-Queue-Id: D13001A0006 X-Stat-Signature: 37kynjjjf7dioqakttkpoewxczwm69md X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674611892-319564 X-HE-Meta: U2FsdGVkX18b23n1RLQmaJHGs7zsJc24AeCiXa03eFBvqdLEXpE/2wVrQ0PhbJUzh+c9gwZzMRofl39Tg2BKthoii/f4szXd/G/PKEIPWhc9cPG3ncCOAITN5eS8uyJLDux8tA9UhCaLrmK/kqqvcdo/5tl5SJvrc4i2p6YXumH0+3pSgrLNwyFbRaAnmBpe2v4htIiW+XfJCk5z6xwUBoqjXkpHWxWJ0bodNIMwAOOPuJwipNoFj00EZSDHPjvdoZaVGwfg/RjBI4t4YDX8J3plox3XZn6KyEXkjdyZ1LigcVRhXZr4iNHqFIsmeDmVhE3162hn1nF8Xsfc8gUsvllpxJLkGrsJ6/8s1RSEz4UH0GZsqfxLz+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GvpN1mu2qQY9rWqTaDLMK1xRYbDNPxwBxZIIGdCxtK5N1LVw7pochP2EN+Fl3l1oeEBH99J3GH1rfUlBfwBvuGS2fcLRW0d1PWLDzCR19vObQ1iof3YOcb0Eja6zTftjxFb+Z4uH3n13HOpvvCaxLU8LHud1IZHxT33pdSJYxx54NO3RdnF/dV9m6tB/9uzpkqMCOH4CVmmZvCVuyNcPHoInw= 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: During collapse, in a few places we check to see if a given small page has any unaccounted references. If the refcount on the page doesn't match our expectations, it must be there is an unknown user concurrently interested in the page, and so it's not safe to move the contents elsewhere. However, the unaccounted pins are likely an ephemeral state. In such a situation, make MADV_COLLAPSE set EAGAIN errno, indicating that collapse may succeed on retry. Fixes: 7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse") Reported-by: Hugh Dickins Signed-off-by: Zach O'Keefe Reviewed-by: Yang Shi Acked-by: Hugh Dickins --- mm/khugepaged.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e23619bfecc4..fa38cae240b9 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2712,6 +2712,7 @@ static int madvise_collapse_errno(enum scan_result r) case SCAN_CGROUP_CHARGE_FAIL: return -EBUSY; /* Resource temporary unavailable - trying again might succeed */ + case SCAN_PAGE_COUNT: case SCAN_PAGE_LOCK: case SCAN_PAGE_LRU: case SCAN_DEL_PAGE_LRU: