From patchwork Wed Nov 10 18:54:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12612579 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 CEE4DC4321E for ; Wed, 10 Nov 2021 18:54:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 858AD61241 for ; Wed, 10 Nov 2021 18:54:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 858AD61241 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 E171B6B007B; Wed, 10 Nov 2021 13:54:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC7A06B007D; Wed, 10 Nov 2021 13:54:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A366B007E; Wed, 10 Nov 2021 13:54:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id A24D36B007B for ; Wed, 10 Nov 2021 13:54:44 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 63FE882EDA69 for ; Wed, 10 Nov 2021 18:54:44 +0000 (UTC) X-FDA: 78793922088.14.71D111A Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf29.hostedemail.com (Postfix) with ESMTP id B4E3C900026D for ; Wed, 10 Nov 2021 18:54:43 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id 200so3079145pga.1 for ; Wed, 10 Nov 2021 10:54:43 -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=rBT2i+ibMjUPU+GMHVeJgDSAZS9LepQWxKEn+dMw9ss=; b=HE1VtepJ2PS853W26g8BxvOJj0oddXOBuT8SM4C+AVExvK+IHF5btQZQzPIKMgcUXG nvjIfVPSWeiykHx3g4VGCNPay8IHl1PnA38Dn89Bw8098fMEvG+g8u1UdbBY1BCXHsGZ 1mCp4j4eXJKZ2E476SCX60fS1KBzoqsDnvVvp35OWKIvMzIWIlwXa8vNt7lNXrJ/edtM 0d910Ub+JXNH2YpTiVW18kiSl2OYB/0mBOK1DzOry2+3T4B030PPZlLELyaUV+Hynjih VoKXkZ2aTYAuw3GfK0af2ALR4h+87ypZFTbPaPNv2EaclU27UOaEY/OCdu7vhasU6riO 0HHw== 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=rBT2i+ibMjUPU+GMHVeJgDSAZS9LepQWxKEn+dMw9ss=; b=OFxxxixl0sQFAlIk94vTx95W4RFOrT8EGnnvFwG46/xfWNdtYBeEP+A7ZycNIADP+z J44t0OYdaLMnJlsQXMjNMSE2pztHH6PxG+Vfz7ISwl2j35YhCvayLt4rjjCsAcs1rHNf sB7AZExWVeZ3bF59/De9DMZnWxRGkeMjCE8QqdsDUtUG7wQM/BUV8RLVwmPGOsSvNUfK iAxy+yu9OHOTmGkcpI2hb98mGFGQg7qi8FkSccfJHca/c0tyORH1usFhHoaaSmrSB7mO K2rpPM/OUVHS/EZeCUA10RmEGm56jww3yGtggDlWNKf+w5G/OfomX/1c3Zj7mb2qYdiZ 2TUw== X-Gm-Message-State: AOAM531+BTQPh8+0qkPP+HhNoQE312h445I+sMuaScCxteqwfMU4uqm+ 4GG5Qt8JpoYyB1FYbRXpA74jCVV/snQ= X-Google-Smtp-Source: ABdhPJyoCbS6G0fcEYb54n+jZgGeFlAYJ4BrIead0n7kGepL4Y4oQMWrZeqwfX1fKxy17+7TdkO0vg== X-Received: by 2002:a05:6a00:1996:b0:49f:d1b0:5d1f with SMTP id d22-20020a056a00199600b0049fd1b05d1fmr1276259pfl.36.1636570482734; Wed, 10 Nov 2021 10:54:42 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:11d4:2de3:ab82:be64]) by smtp.gmail.com with ESMTPSA id g13sm325253pjc.39.2021.11.10.10.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 10:54:42 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: Sergey Senozhatsky , linux-mm , Minchan Kim Subject: [PATCH 5/8] zsmalloc: move huge compressed obj from page to zspage Date: Wed, 10 Nov 2021 10:54:30 -0800 Message-Id: <20211110185433.1981097-6-minchan@kernel.org> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211110185433.1981097-1-minchan@kernel.org> References: <20211110185433.1981097-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B4E3C900026D X-Stat-Signature: te8neidhahupow8fjcfyw99eg1fhm41k Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HE1VtepJ; spf=pass (imf29.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.215.180 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: 1636570483-122679 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 8f9cd07033de..da15d98a6e29 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); @@ -1866,7 +1868,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)); }