From patchwork Tue Apr 26 14:44:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12827332 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 C27FDC433FE for ; Tue, 26 Apr 2022 14:44:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 882516B0088; Tue, 26 Apr 2022 10:44:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 830776B0089; Tue, 26 Apr 2022 10:44:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A8CD6B008A; Tue, 26 Apr 2022 10:44:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 5D0786B0088 for ; Tue, 26 Apr 2022 10:44:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 387E560B66 for ; Tue, 26 Apr 2022 14:44:44 +0000 (UTC) X-FDA: 79399301688.04.1A80A03 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 66DF110004D for ; Tue, 26 Apr 2022 14:44:37 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id bj12-20020a056a02018c00b003a9eebaad34so10979357pgb.10 for ; Tue, 26 Apr 2022 07:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LAOtWTUOjibEYKJGTookHxRPRUx2k2aCGFDTN9t6IEM=; b=ZV+LROzrj5YMGO/m+Stfrf7RzVl+FVzUYE+3ij/We2j8GgRKIaV7VJsmMnHChtQXGH V3QGfqvsnK2lSuq5nMh7jVj3irpYnyCPiOFZYshU86P/YxIE5IdWPq0ODtz+NsOlbUp7 gMg6/f/1IN04B0aqmdkN8g/L90k/KCyfnOXC8e0R+PoAyVuC+c33IYkn6xDM5gOKsgug pySO2f1YfSjGxpCSr8w00hB7DVYRBjStQhCCpU07Ic2lmedVFrLTpze1Urm0rTAQov6C llMxWjWsfN/2WapiqmrWax14UppZhZPuqy4fJUscGYoQExtoT37LCyM5HoCUSmLcIIt8 b5xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LAOtWTUOjibEYKJGTookHxRPRUx2k2aCGFDTN9t6IEM=; b=Oh7zwSTkRRY2c5mzxOhK/vQDdVfaw70EfjeCplFlYsjABKniMAKBb+ATe58Wq6pa70 KwJOX/tryJBmWBatAHKxt546uPsE4WQGGnRJOirybhM7rgk9ty3p6yr+lchj8b+DEUFj omoJS8ZtCZJhTjaANj7J6LulIawo9dyLkd8QvytvG6Vx+NPomOY/uT5pZLFFibmyjONe FB/sChdPkzgyiiNQx3bXfW1jhkNayRTThCFIWaP1UB5VA1QyUEaHP8iM/iwoVUQTu7lR CcnntjI8c1mzxXFoRhoOqo6Uj3NbaNZ7GCcRtQfz+3Yt3HkM5V9YHp76zpeUkpDlIJya 109g== X-Gm-Message-State: AOAM531xD/AI8Za31n6Aynys8rBLPPOZRGXQXJrY0NMf1xbtTSbHv1K9 68nbhOx5Ce/OGXwaakaaqzoR030+Knmc X-Google-Smtp-Source: ABdhPJx6v1U9D7lGFryHGE+cHFVM8rQP5aJ7X3bdJh/0RUAhHv6GDcud5QFIygOwcT3I4yVCui8H4oyJtd7B X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:1895:b0:50a:de86:b4b0 with SMTP id x21-20020a056a00189500b0050ade86b4b0mr24802185pfh.28.1650984282754; Tue, 26 Apr 2022 07:44:42 -0700 (PDT) Date: Tue, 26 Apr 2022 07:44:12 -0700 In-Reply-To: <20220426144412.742113-1-zokeefe@google.com> Message-Id: <20220426144412.742113-13-zokeefe@google.com> Mime-Version: 1.0 References: <20220426144412.742113-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 12/12] selftests/vm: add test to verify recollapse of THPs From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Peter Xu , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: 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 , "Zach O'Keefe" Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZV+LROzr; spf=pass (imf05.hostedemail.com: domain of 3WgVoYgcKCB8UJF99A9BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--zokeefe.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3WgVoYgcKCB8UJF99A9BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 66DF110004D X-Stat-Signature: ffxziddmt7s6schnq3qg3u4qjmcyoqxn X-HE-Tag: 1650984277-855769 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: Add selftest specific to madvise collapse context that tests MADV_COLLAPSE is "successful" if a hugepage-algined/sized region is already pmd-mapped. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index e0ccc9443f78..c36d04218083 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -969,6 +969,32 @@ static void collapse_max_ptes_shared(struct collapse_context *context) munmap(p, hpage_pmd_size); } +static void madvise_collapse_existing_thps(void) +{ + void *p; + int err; + + p = alloc_mapping(); + fill_memory(p, 0, hpage_pmd_size); + + printf("Collapse fully populated PTE table..."); + madvise(p, hpage_pmd_size, MADV_HUGEPAGE); + err = madvise(p, hpage_pmd_size, MADV_COLLAPSE); + if (err == 0 && check_huge(p)) { + success("OK"); + printf("Re-collapse PMD-mapped hugepage"); + err = madvise(p, hpage_pmd_size, MADV_COLLAPSE); + if (err == 0 && check_huge(p)) + success("OK"); + else + fail("Fail"); + } else { + fail("Fail"); + } + validate_memory(p, 0, hpage_pmd_size); + munmap(p, hpage_pmd_size); +} + static void madvise_collapse(const char *msg, char *p, bool expect) { int ret; @@ -1097,6 +1123,7 @@ int main(void) alloc_at_fault(); + /* Shared tests */ for (i = 0; i < sizeof(contexts) / sizeof(contexts[0]); ++i) { struct collapse_context *c = &contexts[i]; @@ -1119,5 +1146,10 @@ int main(void) break; } + /* madvise-specific tests */ + disable_khugepaged(); + madvise_collapse_existing_thps(); + enable_khugepaged(); + restore_settings(0); }