From patchwork Mon Nov 15 18:59:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12620229 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64538C433FE for ; Mon, 15 Nov 2021 18:59:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1964E6368A for ; Mon, 15 Nov 2021 18:59:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1964E6368A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B43936B007E; Mon, 15 Nov 2021 13:59:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACC3D6B0080; Mon, 15 Nov 2021 13:59:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91D1A6B0081; Mon, 15 Nov 2021 13:59:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 83F3B6B007E for ; Mon, 15 Nov 2021 13:59:20 -0500 (EST) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4D34B84CE2 for ; Mon, 15 Nov 2021 18:59:20 +0000 (UTC) X-FDA: 78812077680.36.850736D Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf27.hostedemail.com (Postfix) with ESMTP id C6E5470009CE for ; Mon, 15 Nov 2021 18:59:19 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id g28so15381605pgg.3 for ; Mon, 15 Nov 2021 10:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BWDMmjqynWZEAd9h9yKAs1pSujUR3PfRIBQcnnobkdE=; b=cGyp/bWHN50rNMxDmiuZEHaXRJEeRkWOdSakIX0N4UwOYhdSBFeMyR0uyEDlXphM2V uZ5ciB4CuOVSOnKC9vu6SGqyw+eQG8q+KwyQO6om8iGrVik95do8EHG79t/NCWMn05A6 QXT/CDwlhsUjgTaWjT2ZqzCa49XdfHK1fmkMOYFrc+CXuqAZ7S6l20qrwJaTd1l2tZtE WmqS4Kz9lSOOuefNctrbvZFvM9/CxCQU1tk+vNieCFdA7tTKXuIB62uB6WMGshNf0IiX +YQPmi/1UoUzPUeW7+mE4oMkKnQCvuG6xA1XOY2q1DiURcBes1WKse1rUCCnEP2UON5w 0mmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BWDMmjqynWZEAd9h9yKAs1pSujUR3PfRIBQcnnobkdE=; b=s8kmmt85ajtx8A7Vq9vQbRyqSqvkn3jswFtqkFk82uRDzgSXOAoIHmn0a+IOJFau9a 8GyrLC6adxDhl9ru3j/qhAr+AcnTp2kXCOC4xfGJSAUgQQ+annjLQAk1r4AUngGeJg9O sMNbfn5NQxQfivG0VA5dPbEWJKB3KqprgNpjWKZVDPKqpUukwn1H4iVddoul0OfwFArT a8pmkkbl8cgXWO7AC+J7oqzhmbjGwltiBObKZwXVZb8pV0k8yDvPN7LaHYY6kkelJYMk pKynaAglidXt6tC8598mlLFtiNNfasRRclr7xyjBm8rn3FGAiNVVT7JIYQy+ajKdRTgG Okeg== X-Gm-Message-State: AOAM533ldT+J1VjqRp6mX8IblNDUNY94Jg+Vk/tMJF29td4dfDkiWcrs Vjp2JcPZlPilvCpAKNs8ifs= X-Google-Smtp-Source: ABdhPJxRww3aWuI1I1XEJ4dSrjY48BDA9+C8l/r6j0Lk5KgQVsKDok4BYLh5U2AamCmcsl+iYK4QyQ== X-Received: by 2002:a63:7cd:: with SMTP id 196mr747749pgh.224.1637002758896; Mon, 15 Nov 2021 10:59:18 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:7a54:8083:4365:b23d]) by smtp.gmail.com with ESMTPSA id c3sm11882941pfv.67.2021.11.15.10.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 10:59:17 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: Sergey Senozhatsky , linux-mm , LKML , Minchan Kim Subject: [PATCH v2 5/9] zsmalloc: move huge compressed obj from page to zspage Date: Mon, 15 Nov 2021 10:59:05 -0800 Message-Id: <20211115185909.3949505-6-minchan@kernel.org> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211115185909.3949505-1-minchan@kernel.org> References: <20211115185909.3949505-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C6E5470009CE X-Stat-Signature: d1pt795zar4yk7n6sqxydsixm39nsh6j Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="cGyp/bWH"; spf=pass (imf27.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-HE-Tag: 1637002759-388122 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: the flag aims for zspage, not per page. Let's move it to zspage. Signed-off-by: Minchan Kim --- mm/zsmalloc.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 6ca130c0f7dc..26e571cc354e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -121,6 +121,7 @@ #define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS) #define OBJ_INDEX_MASK ((_AC(1, UL) << OBJ_INDEX_BITS) - 1) +#define HUGE_BITS 1 #define FULLNESS_BITS 2 #define CLASS_BITS 8 #define ISOLATED_BITS 3 @@ -213,22 +214,6 @@ struct size_class { struct zs_size_stat stats; }; -/* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ -static void SetPageHugeObject(struct page *page) -{ - SetPageOwnerPriv1(page); -} - -static void ClearPageHugeObject(struct page *page) -{ - ClearPageOwnerPriv1(page); -} - -static int PageHugeObject(struct page *page) -{ - return PageOwnerPriv1(page); -} - /* * Placed within free objects to form a singly linked list. * For every zspage, zspage->freeobj gives head of this list. @@ -278,6 +263,7 @@ struct zs_pool { struct zspage { struct { + unsigned int huge:HUGE_BITS; unsigned int fullness:FULLNESS_BITS; unsigned int class:CLASS_BITS + 1; unsigned int isolated:ISOLATED_BITS; @@ -298,6 +284,17 @@ struct mapping_area { enum zs_mapmode vm_mm; /* mapping mode */ }; +/* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ +static void SetZsHugePage(struct zspage *zspage) +{ + zspage->huge = 1; +} + +static bool ZsHugePage(struct zspage *zspage) +{ + return zspage->huge; +} + #ifdef CONFIG_COMPACTION static int zs_register_migration(struct zs_pool *pool); static void zs_unregister_migration(struct zs_pool *pool); @@ -830,7 +827,9 @@ static struct zspage *get_zspage(struct page *page) static struct page *get_next_page(struct page *page) { - if (unlikely(PageHugeObject(page))) + struct zspage *zspage = get_zspage(page); + + if (unlikely(ZsHugePage(zspage))) return NULL; return page->freelist; @@ -880,8 +879,9 @@ static unsigned long handle_to_obj(unsigned long handle) static bool obj_allocated(struct page *page, void *obj, unsigned long *phandle) { unsigned long handle; + struct zspage *zspage = get_zspage(page); - if (unlikely(PageHugeObject(page))) { + if (unlikely(ZsHugePage(zspage))) { VM_BUG_ON_PAGE(!is_first_page(page), page); handle = page->index; } else @@ -920,7 +920,6 @@ static void reset_page(struct page *page) ClearPagePrivate(page); set_page_private(page, 0); page_mapcount_reset(page); - ClearPageHugeObject(page); page->freelist = NULL; } @@ -1062,7 +1061,7 @@ static void create_page_chain(struct size_class *class, struct zspage *zspage, SetPagePrivate(page); if (unlikely(class->objs_per_zspage == 1 && class->pages_per_zspage == 1)) - SetPageHugeObject(page); + SetZsHugePage(zspage); } else { prev_page->freelist = page; } @@ -1307,7 +1306,7 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, ret = __zs_map_object(area, pages, off, class->size); out: - if (likely(!PageHugeObject(page))) + if (likely(!ZsHugePage(zspage))) ret += ZS_HANDLE_SIZE; return ret; @@ -1395,7 +1394,7 @@ static unsigned long obj_malloc(struct zs_pool *pool, vaddr = kmap_atomic(m_page); link = (struct link_free *)vaddr + m_offset / sizeof(*link); set_freeobj(zspage, link->next >> OBJ_TAG_BITS); - if (likely(!PageHugeObject(m_page))) + if (likely(!ZsHugePage(zspage))) /* record handle in the header of allocated chunk */ link->handle = handle; else @@ -1496,7 +1495,10 @@ static void obj_free(int class_size, unsigned long obj) /* Insert this object in containing zspage's freelist */ link = (struct link_free *)(vaddr + f_offset); - link->next = get_freeobj(zspage) << OBJ_TAG_BITS; + if (likely(!ZsHugePage(zspage))) + link->next = get_freeobj(zspage) << OBJ_TAG_BITS; + else + f_page->index = 0; kunmap_atomic(vaddr); set_freeobj(zspage, f_objidx); mod_zspage_inuse(zspage, -1); @@ -1867,7 +1869,7 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, create_page_chain(class, zspage, pages); set_first_obj_offset(newpage, get_first_obj_offset(oldpage)); - if (unlikely(PageHugeObject(oldpage))) + if (unlikely(ZsHugePage(zspage))) newpage->index = oldpage->index; __SetPageMovable(newpage, page_mapping(oldpage)); }