From patchwork Sat Feb 18 00:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13145410 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 3353AC05027 for ; Sat, 18 Feb 2023 00:30:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC30F6B007E; Fri, 17 Feb 2023 19:29:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A73006B0081; Fri, 17 Feb 2023 19:29:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EC006B0082; Fri, 17 Feb 2023 19:29:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7FA576B007E for ; Fri, 17 Feb 2023 19:29:47 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 57E8D80723 for ; Sat, 18 Feb 2023 00:29:47 +0000 (UTC) X-FDA: 80478529614.25.4AC2B11 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 9E1E210000B for ; Sat, 18 Feb 2023 00:29:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CawVGssL; spf=pass (imf05.hostedemail.com: domain of 3-BvwYwoKCBc6G4BH34GBA3BB381.zB985AHK-997Ixz7.BE3@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3-BvwYwoKCBc6G4BH34GBA3BB381.zB985AHK-997Ixz7.BE3@flex--jthoughton.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=1676680185; 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=hyOLv1FsgINJ0DL+GVviZenHuSxZX0xiNJERAdFTwJY=; b=hdWl+RRautAht2LWXbKvcyJLqR3TmKVBLbd/HZWB0rPfzuonMRTqHH6h/OzMcvp6P82S1Y W2bOUPl5zmwcf1GUNmMO5rn6PSlAha/qsZGKwdyWSJg4huBAkBLP0hza9CG4DNN1ibRN75 AOaz/de2eBpiBEFGUPqeQY6kfygMeFc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CawVGssL; spf=pass (imf05.hostedemail.com: domain of 3-BvwYwoKCBc6G4BH34GBA3BB381.zB985AHK-997Ixz7.BE3@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3-BvwYwoKCBc6G4BH34GBA3BB381.zB985AHK-997Ixz7.BE3@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680185; a=rsa-sha256; cv=none; b=4+Ylq1Q6tVc3HYHLXXzgnm8VTnLbNq1jbyshUYYHBXd4UZPAvZlsTPIJ44AfvTDx6VvPkR zzYiAkNGlhjuyxpl/ajV5+LBrgPlBGMg/jxlcVFVCpkMepHfWShfcDEOfTWQH8F0D/hwhR 4ABHQrVkFs7W3CPg0oFWZxN+RFezgpU= Received: by mail-yb1-f202.google.com with SMTP id e128-20020a253786000000b009433a21be0dso2009367yba.19 for ; Fri, 17 Feb 2023 16:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hyOLv1FsgINJ0DL+GVviZenHuSxZX0xiNJERAdFTwJY=; b=CawVGssLxbR/eBsnpR76uSOwVJlkmsmCv0a5oroE0FUoq5CLC5qHPXGXefy+nfOAyq vHPyCbLQuykbScgNRy8G6ArFuhS2PA24tAoAR0gKyBhUDTykhHwShI6arftzkplVbyyk b4WDZ3892nTCDc681eGtskse+KIsH+dqtfTG2Vne6aDgRhNRdxfjHtbN/sR4SQs6gHc0 qUEwaDcngWDaQt95+PjWHSmLfyKw65IbdY5tMd2l4nt3+4TnGgT5wI1VLYvFO5GyJcwD HDiIQ3YFBSVkmnMVLHQ4cyRGkHdEevZ48y3mNmJQPrsPUHrSdwcp+QpVtufpdBI9D2OH id0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hyOLv1FsgINJ0DL+GVviZenHuSxZX0xiNJERAdFTwJY=; b=7zZwZix/ml55bKggS35UGI9Tbe5yMjCUshMHIojRh+5RPoQCWnF/CHchhR2LK09+aB qqPqc1KLfrL+SK390esp8F0K1uIofFFB4ZyF80+uI066tGZq8+JSPdpbJAUgGlxJXXb4 ZQJBENXuucYmK+aaP5RSpbh0jsKXYUmxMGKQNhqE0wTsqKjDwTGtLJXNp3P8DfO+CXt/ U6xvJvxn7OaJy4FAyA6sQ7St1WDW497MN8RF7po8heQB4YVZ2OGsB1Wo+kDh3N2KB/g9 LX6WCoXcMefn4IVwSI7M1TcYMUGCbWmmjmOo/BWuSexz4u3my5my9+WTE0PJs+rJVtsu uzGQ== X-Gm-Message-State: AO0yUKXWvQCXxh2vcolWMdluVUgBCpCoVxY+WoJaUrQuG9okuECEXlg0 qJqRzJlYBS3NULkdmvMYDAvcNRYinJOvTk+B X-Google-Smtp-Source: AK7set+1gp+3xzyRWa+pkBelE3wO17FQrBJLukvYGoDbOlAPndL6HG5Z6zOqFqMyhLaMuLWmUDnySY104VSUsagh X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:4f0:b0:98e:6280:74ca with SMTP id w16-20020a05690204f000b0098e628074camr174263ybs.1.1676680184745; Fri, 17 Feb 2023 16:29:44 -0800 (PST) Date: Sat, 18 Feb 2023 00:28:17 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-45-jthoughton@google.com> Subject: [PATCH v2 44/46] selftests/mm: add anon and shared hugetlb to migration test From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Frank van der Linden , Jiaqi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Stat-Signature: u8rwmc6m316khz9jkfdtrbo81bgwd8rr X-Rspam-User: X-Rspamd-Queue-Id: 9E1E210000B X-Rspamd-Server: rspam06 X-HE-Tag: 1676680185-754805 X-HE-Meta: U2FsdGVkX18BUNDvX6HQkcWYy1h/kg4lZaMo8uA3ToHNjPRgTgceTxfVldhDBzHiCSr9c45lCoG3pxxdkXCfrQ7gbRvxng22CBjJRYDGKVhTtFGKr25kxkiAPxcBaYxBJbPddL8vKZjd6F23G8bHTL9USuOL8R4qjb+VQeY0pTEpHMDOl+fB5nJOp4hNH/u44+LP8Ovr0bx1G4eKPksgbb4lttoQAz3qR7uxglqCQlxo+HEVKrJUWpsrIoh1QicZqcyR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nQUiwuj1wlDEa0SZtoNqCFo9RFmJcXU6VR84tdZoazgII5rRbWsFg8gZJxznN7vvn6AKyz6zjIISXMLzqO/0jRAJTU/Zh4VBf6uuDfbA9lWp5evUxgdJHb9rv368Z45NmR5gqxwfXE/qDIssXPh2XBAMluqEJt8cBs4AbKY8hGDwbzGa/lZMRFEUyxfn1qs13CZ8ztKRVamfiIBU71unelK0Ur7f0JktnJoHt5FPwyuuKxLeWq6 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: Shared HugeTLB mappings are migrated best-effort. Sometimes, due to being unable to grab the VMA lock for writing, migration may just randomly fail. To allow for that, we allow retries. Signed-off-by: James Houghton diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c index 1cec8425e3ca..21577a84d7e4 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -13,6 +13,7 @@ #include #include #include +#include #define TWOMEG (2<<20) #define RUNTIME (60) @@ -59,11 +60,12 @@ FIXTURE_TEARDOWN(migration) free(self->pids); } -int migrate(uint64_t *ptr, int n1, int n2) +int migrate(uint64_t *ptr, int n1, int n2, int retries) { int ret, tmp; int status = 0; struct timespec ts1, ts2; + int failed = 0; if (clock_gettime(CLOCK_MONOTONIC, &ts1)) return -1; @@ -78,6 +80,9 @@ int migrate(uint64_t *ptr, int n1, int n2) ret = move_pages(0, 1, (void **) &ptr, &n2, &status, MPOL_MF_MOVE_ALL); if (ret) { + if (++failed < retries) + continue; + if (ret > 0) printf("Didn't migrate %d pages\n", ret); else @@ -88,6 +93,7 @@ int migrate(uint64_t *ptr, int n1, int n2) tmp = n2; n2 = n1; n1 = tmp; + failed = 0; } return 0; @@ -128,7 +134,7 @@ TEST_F_TIMEOUT(migration, private_anon, 2*RUNTIME) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); - ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); + ASSERT_EQ(migrate(ptr, self->n1, self->n2, 1), 0); for (i = 0; i < self->nthreads - 1; i++) ASSERT_EQ(pthread_cancel(self->threads[i]), 0); } @@ -158,7 +164,7 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME) self->pids[i] = pid; } - ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); + ASSERT_EQ(migrate(ptr, self->n1, self->n2, 1), 0); for (i = 0; i < self->nthreads - 1; i++) ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); } @@ -185,9 +191,78 @@ TEST_F_TIMEOUT(migration, private_anon_thp, 2*RUNTIME) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); - ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); + ASSERT_EQ(migrate(ptr, self->n1, self->n2, 1), 0); + for (i = 0; i < self->nthreads - 1; i++) + ASSERT_EQ(pthread_cancel(self->threads[i]), 0); +} + +/* + * Tests the anon hugetlb migration entry paths. + */ +TEST_F_TIMEOUT(migration, private_anon_hugetlb, 2*RUNTIME) +{ + uint64_t *ptr; + int i; + + if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) + SKIP(return, "Not enough threads or NUMA nodes available"); + + ptr = mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); + if (ptr == MAP_FAILED) + SKIP(return, "Could not allocate hugetlb pages"); + + memset(ptr, 0xde, TWOMEG); + for (i = 0; i < self->nthreads - 1; i++) + if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) + perror("Couldn't create thread"); + + ASSERT_EQ(migrate(ptr, self->n1, self->n2, 1), 0); for (i = 0; i < self->nthreads - 1; i++) ASSERT_EQ(pthread_cancel(self->threads[i]), 0); } +/* + * Tests the shared hugetlb migration entry paths. + */ +TEST_F_TIMEOUT(migration, shared_hugetlb, 2*RUNTIME) +{ + uint64_t *ptr; + int i; + int fd; + unsigned long sz; + struct statfs filestat; + + if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) + SKIP(return, "Not enough threads or NUMA nodes available"); + + fd = memfd_create("tmp_hugetlb", MFD_HUGETLB); + if (fd < 0) + SKIP(return, "Couldn't create hugetlb memfd"); + + if (fstatfs(fd, &filestat) < 0) + SKIP(return, "Couldn't fstatfs hugetlb file"); + + sz = filestat.f_bsize; + + if (ftruncate(fd, sz)) + SKIP(return, "Couldn't allocate hugetlb pages"); + ptr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (ptr == MAP_FAILED) + SKIP(return, "Could not map hugetlb pages"); + + memset(ptr, 0xde, sz); + for (i = 0; i < self->nthreads - 1; i++) + if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) + perror("Couldn't create thread"); + + ASSERT_EQ(migrate(ptr, self->n1, self->n2, 10), 0); + for (i = 0; i < self->nthreads - 1; i++) { + ASSERT_EQ(pthread_cancel(self->threads[i]), 0); + pthread_join(self->threads[i], NULL); + } + ftruncate(fd, 0); + close(fd); +} + TEST_HARNESS_MAIN