Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp462049pxf; Thu, 8 Apr 2021 06:45:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5VCTvccvEFWXYM0TTuEFkYRJRMNLRya3XEY1Ie8jopvk4jbjxlPodyQBESuZUCZXcYr1k X-Received: by 2002:a17:90a:7c4b:: with SMTP id e11mr8375751pjl.151.1617889514759; Thu, 08 Apr 2021 06:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617889514; cv=none; d=google.com; s=arc-20160816; b=Lip1X7NCX/0g8/osQEpEg//kyJ0ww6nfgkXQkEMx6LUqwf2LHp/JiZR/CjY/HmbC4B dtnhn3Dd+wsdnXReV0jVB9oaMbptFkoZakAuJ7vlg/BtHVvD8fOQOwJb75iZUgxa8EDQ 79JQo0VWH3yQQPyhG+Ue+dIJ6GHnY+Oan9knRKgZvumvMWq5XhmU4gdlhmS7OoUDG0h+ S60UXIEAM3aA+pT1wJQPbhfZe7mzOGKVI/ZPEpK32glrKw5sZ/Qti71HqbXPdUHs6a8X YF3DUSPTlZZNPC8jc2vhnE7d82Tu9P1mLaqWZFOnBebltFC0luY2mKUkImtwddPsMqDX 9STQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=ptn81a+fQuQgZnciPG4/Q0mKxLqutQak+90Q0cVPhg4=; b=NMTtP+nzQLui1MVS14606aRQY5aTbHxXuczzwA7b317QKqhK3BsN5940I2sZHtAztw W0xfVV3UFqlTola1anbqkSngKu7wcuuh7L3D80JyR4FJEMxjHbL+GziKHUNLDKIG367S hAz8NJpS0vMQRmXC78CIW7TejvyxerLkwyeH32eaHGuewg7DE6+NPPPXUddk2TfMtJ5T whz5xwHuEVVUm/WswXbLOVKKTPAJ+92bI0TFEJM0c5vYFQEeT3YUlsXV1kPGMAe78fa9 jXlXxNcFZiMaZPnqQwkSEmf58R4z0j0hTkDcGgIBpXqnxz3XZQQkxNAb7LLP9DcmIro8 FBrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s126si28602632pfs.269.2021.04.08.06.44.54; Thu, 08 Apr 2021 06:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231672AbhDHNnS (ORCPT + 99 others); Thu, 8 Apr 2021 09:43:18 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:14517 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhDHNnS (ORCPT ); Thu, 8 Apr 2021 09:43:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=teawaterz@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0UUu0lrj_1617889378; Received: from localhost(mailfrom:teawaterz@linux.alibaba.com fp:SMTPD_---0UUu0lrj_1617889378) by smtp.aliyun-inc.com(127.0.0.1); Thu, 08 Apr 2021 21:43:06 +0800 From: Hui Zhu To: wufengguang@huawei.com, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH for vm-scalability] usemem: Add code for touch-alloc Date: Thu, 8 Apr 2021 21:42:55 +0800 Message-Id: <20210408134255.12330-1-teawater@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add code for touch-alloc. And Change read memory to write memory to avoid use the zero-page for reads in do_anonymous_page. Signed-off-by: Hui Zhu --- usemem.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/usemem.c b/usemem.c index e2c46ec..5b90aae 100644 --- a/usemem.c +++ b/usemem.c @@ -329,6 +329,18 @@ void detach(void) } } +unsigned long do_access(unsigned long *p, unsigned long idx, int read) +{ + volatile unsigned long *vp = p; + + if (read) + return vp[idx]; /* read data */ + else { + vp[idx] = idx; /* write data */ + return 0; + } +} + unsigned long * allocate(unsigned long bytes) { unsigned long *p; @@ -355,6 +367,14 @@ unsigned long * allocate(unsigned long bytes) p = (unsigned long *)ALIGN((unsigned long)p, pagesize - 1); } + if (opt_touch_alloc) { + unsigned long i; + unsigned long m = bytes / sizeof(*p); + + for (i = 0; i < m; i += 1) + do_access(p, i, 0); + } + return p; } @@ -436,18 +456,6 @@ void shm_unlock(int seg_id) shmctl(seg_id, SHM_UNLOCK, NULL); } -unsigned long do_access(unsigned long *p, unsigned long idx, int read) -{ - volatile unsigned long *vp = p; - - if (read) - return vp[idx]; /* read data */ - else { - vp[idx] = idx; /* write data */ - return 0; - } -} - #define NSEC_PER_SEC (1UL * 1000 * 1000 * 1000) long nsec_sub(long nsec1, long nsec2) @@ -953,6 +961,8 @@ int main(int argc, char *argv[]) opt_punch_holes = 1; } else if (strcmp(opts[opt_index].name, "init-time") == 0) { opt_init_time = 1; + } else if (strcmp(opts[opt_index].name, "touch-alloc") == 0) { + opt_touch_alloc = 1; } else usage(1); break; -- 2.17.1