Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1542651rwr; Wed, 26 Apr 2023 17:19:37 -0700 (PDT) X-Google-Smtp-Source: AKy350avfInmviXfFir6lJtSyUXu4AYCJvN9Y5vJj08/GgigBUBMhrZIt6UNH9NMZqYi9IrWrR82 X-Received: by 2002:a17:90a:e150:b0:237:ae7c:15be with SMTP id ez16-20020a17090ae15000b00237ae7c15bemr22921731pjb.30.1682554776760; Wed, 26 Apr 2023 17:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682554776; cv=none; d=google.com; s=arc-20160816; b=TiBzBE6VCyE2GA/GlH2Du8ARIzSxCo3H65Uw2tj4J87Nw46qAD6O5zTPpAe0LW7px5 Ao5nnQDGpVywvaTsJdnq1+yEqCYveiSdLyQPh8oreqUF/bpjRbtFhaLFM0NPXfZ1GBm8 HU6jwfP65sXPyxwEV92qFkvODU4pUKkWVQa2Fa+tFFgPqfTBT9ovnXtLHukTwQW/pcim GNYxPWvyoDexX/2GMiXK/5p7BwwUeF8e+caWbbm9sr+3bS24Wr1Gw+SZJiSbRP8PM2F9 WYxEWq45rIcr1yiBtus7pSMAOR4WB5B/rIqn+NFJ5bA46TKI3Rbn0v5jiiFxViK01NwE vHcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=43eGY+TDyN1Z/nEUhZp/pkRJ381CTkYO9EwFJXyHijs=; b=D5Muqwfhgk+uMKPp5D5SX5PerpJU67HVM7vR8/i8RhZRqqOGyx14JYwarwGGdfw+MN C1w00CuYsdYIRkGJux7C3QV9qni8i413CIGFthx33PVLLxYtmcTux06by7qDnYf+4tLH /RaHScOgr9Bbmeu/Pex1JyOSm7lsdm1g1pVaQ2Z/0n6zuq2TqQV1PGUvfVgfGclf4N/u K9JWnBq/i7oU4CjXOePJw5yS0qriPHYF2BWzD4Mm7XFv6/w+6lDrWVXOCM8i/cVT1IQ8 hyLFYXMZugmxZef3y1afxfnMQSFTxjG1ngUSA1lBz9efWlvCTLHpCyPDu78OmlDaYzBc es0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=lFddECHU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg5-20020a17090b300500b0023409b3983fsi17129041pjb.99.2023.04.26.17.19.25; Wed, 26 Apr 2023 17:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=lFddECHU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242905AbjD0ALJ (ORCPT + 99 others); Wed, 26 Apr 2023 20:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242744AbjD0AKL (ORCPT ); Wed, 26 Apr 2023 20:10:11 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E740D40E0 for ; Wed, 26 Apr 2023 17:10:09 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QGx63C014744; Thu, 27 Apr 2023 00:09:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=43eGY+TDyN1Z/nEUhZp/pkRJ381CTkYO9EwFJXyHijs=; b=lFddECHUFaWe4SvxIWe74XuldZD3XhgVHok2PgKl2CS5V9ILX3LvwHV30JNs3cypkMZR 8uiAfjJTFIhtWlrJRlFDLbAorKgQgvIuVOLrLSEI6IxPSo58U7I0ugig8LUpDtroQYf0 qEQ1xL25lZRaIfxmaXWpRfGNpN5jYkV1m5iS+Qye7WwBzoSapoardIE7ZBZBnESy+/4m gSbsTmhPLiFOZ+wkOz++c0c0sgsqgkb4FrVZUnIxbqFMpcl7ubrUGjWlxLi5zPvEIXaS CguZa3wdyDWhJpmUoSLf4r4OI1kFIpshJwuSTa3CKlRl9yR0fibdnDQCo6NYgE9+jhUZ TA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q47fatmse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:31 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QMn2Cq007147; Thu, 27 Apr 2023 00:09:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618mpu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:31 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33R0938w013888; Thu, 27 Apr 2023 00:09:30 GMT Received: from ca-qasparc-x86-2.us.oracle.com (ca-qasparc-x86-2.us.oracle.com [10.147.24.103]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3q4618mp42-19; Thu, 27 Apr 2023 00:09:30 +0000 From: Anthony Yznaga To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, rppt@kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, keescook@chromium.org, graf@amazon.com, jason.zeng@intel.com, lei.l.li@intel.com, steven.sistare@oracle.com, fam.zheng@bytedance.com, mgalaxy@akamai.com, kexec@lists.infradead.org Subject: [RFC v3 18/21] mm: PKRAM: allow preserved memory to be freed from userspace Date: Wed, 26 Apr 2023 17:08:54 -0700 Message-Id: <1682554137-13938-19-git-send-email-anthony.yznaga@oracle.com> X-Mailer: git-send-email 1.9.4 In-Reply-To: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> References: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_10,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304270000 X-Proofpoint-ORIG-GUID: -W4-EPoCWhe2SX1_zknW2SnhXj4oiT4p X-Proofpoint-GUID: -W4-EPoCWhe2SX1_zknW2SnhXj4oiT4p X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To free all space utilized for preserved memory, one can write 0 to /sys/kernel/pkram. This will destroy all PKRAM nodes that are not currently being read or written. Originally-by: Vladimir Davydov Signed-off-by: Anthony Yznaga --- mm/pkram.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/mm/pkram.c b/mm/pkram.c index 474fb6fc8355..d404e415f3cb 100644 --- a/mm/pkram.c +++ b/mm/pkram.c @@ -493,6 +493,32 @@ static void pkram_truncate_node(struct pkram_node *node) node->obj_pfn = 0; } +/* + * Free all nodes that are not under operation. + */ +static void pkram_truncate(void) +{ + struct page *page, *tmp; + struct pkram_node *node; + LIST_HEAD(dispose); + + mutex_lock(&pkram_mutex); + list_for_each_entry_safe(page, tmp, &pkram_nodes, lru) { + node = page_address(page); + if (!(node->flags & PKRAM_ACCMODE_MASK)) + list_move(&page->lru, &dispose); + } + mutex_unlock(&pkram_mutex); + + while (!list_empty(&dispose)) { + page = list_first_entry(&dispose, struct page, lru); + list_del(&page->lru); + node = page_address(page); + pkram_truncate_node(node); + pkram_free_page(node); + } +} + static void pkram_add_link(struct pkram_link *link, struct pkram_data_stream *pds) { __u64 link_pfn = page_to_pfn(virt_to_page(link)); @@ -1252,8 +1278,19 @@ static ssize_t show_pkram_sb_pfn(struct kobject *kobj, return sprintf(buf, "%lx\n", pfn); } +static ssize_t store_pkram_sb_pfn(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int val; + + if (kstrtoint(buf, 0, &val) || val) + return -EINVAL; + pkram_truncate(); + return count; +} + static struct kobj_attribute pkram_sb_pfn_attr = - __ATTR(pkram, 0444, show_pkram_sb_pfn, NULL); + __ATTR(pkram, 0644, show_pkram_sb_pfn, store_pkram_sb_pfn); static struct attribute *pkram_attrs[] = { &pkram_sb_pfn_attr.attr, -- 1.9.4