Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2647012imd; Fri, 2 Nov 2018 15:17:58 -0700 (PDT) X-Google-Smtp-Source: AJdET5eEVBhBJKAu92AuxfsGwh/zTCNqhy/J9vqeD9l5mBiI5gvuOZq9j4fVWdmX0WTb0PwoziqA X-Received: by 2002:a63:e918:: with SMTP id i24-v6mr12408381pgh.64.1541197078904; Fri, 02 Nov 2018 15:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541197078; cv=none; d=google.com; s=arc-20160816; b=f3uSm06T0XrCgWyZ8J5VZRtBuRF+IlNwpV+BFr3GKkZd0KjTgNrcFM6Yw1FGg78yqz k/TyYlrFTQXjNNirVmhyVw3EMJXv/bmgWuhFS/59hia6MyzpazZZ0qPBzzN3FeLuvVHI Gspw0MLPrf0QhBtOy9MD/aPc+EmrotIJXwK6lcZXZxb6pqrCjBFRfuLLVGXHMwna+aFn m1tlYe0uFMRP4Shz+Ho1JxRfDhmH4WmvrroQSPLT0lYGVhhz6VBqev1fpfHmKqqqL2Jv RNnOd7iJLLMS99G2sAJNkAjAkn1Yyz9FqhVLoJW00lu76GvR6pL4VaGhn9C6O9WE4h8U 80xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=za1nXd44yN1PaHhD+EtnLgm8MlT1vghsYZeuUlnXQDo=; b=iykWJTOSUsgAcqkAVvNyB+K9Us4UU5VvXBFPLY5a2P1kJTN2DPx4NNGF3OKq4d6Wit yQAi+BoaT6pVDljOGMzUq+hE6PkpIPyJH5AS+6FGFJCTpRhy0quDnXQ3inSE4D4ML89O wENMuD9G5E+/aQnsKLtPjA8lDmLWdMqIWM+Rc89HYeyASI28fiD5eJoCLJNlG0258NqQ K9SCbmBLqVGeoAgHCudThTzqGNG+t69MDqgN7Gu8CyaQe+LNmVTkfEMVxYkiydYBSkp3 cQPS0qLVWUJrKpoLImZH+2dYENr05ijkEkn/SLRDzCJzTsNHsWOJSl/8D2vsILTuvlsM SO+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q61-v6si27900483plb.418.2018.11.02.15.17.44; Fri, 02 Nov 2018 15:17:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728555AbeKCHZv (ORCPT + 99 others); Sat, 3 Nov 2018 03:25:51 -0400 Received: from mga18.intel.com ([134.134.136.126]:12704 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728505AbeKCHZv (ORCPT ); Sat, 3 Nov 2018 03:25:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Nov 2018 15:16:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,457,1534834800"; d="scan'208";a="104855231" Received: from kohsamui.iil.intel.com (HELO [10.236.193.12]) ([10.236.193.12]) by fmsmga001.fm.intel.com with ESMTP; 02 Nov 2018 15:16:51 -0700 Subject: Re: lib/genalloc To: Daniel Mentz Cc: Stephen Bates , Mathieu Desnoyers , lkml , labbott@redhat.com References: <4DECD467-AD45-419D-8F0F-1456863274FD@raithlin.com> From: Alexey Skidanov Message-ID: <7a3eb4d7-2a93-8a39-c696-675053e53c53@intel.com> Date: Sat, 3 Nov 2018 00:18:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/2/18 11:16 PM, Daniel Mentz wrote: > On Fri, Nov 2, 2018 at 1:55 PM Alexey Skidanov > wrote: >> >> >> >> On 11/2/18 9:17 PM, Daniel Mentz wrote: >>> On Thu, Nov 1, 2018 at 10:07 AM Alexey Skidanov >>> wrote: >>>> On 11/1/18 18:48, Stephen Bates wrote: >>>>>> I use gen_pool_first_fit_align() as pool allocation algorithm allocating >>>>>> buffers with requested alignment. But if a chunk base address is not >>>>>> aligned to the requested alignment(from some reason), the returned >>>>>> address is not aligned too. >>>>> >>>>> Alexey >>>>> >>>>> Can you try using gen_pool_first_fit_order_align()? Will that give you the alignment you need? >>>>> >>>>> Stephen >>>>> >>>>> >>>> I think it will not help me. Let's assume that the chunk base address is >>>> 0x2F400000 and I want to allocate 16MB aligned buffer. I get back the >>>> 0x2F400000. I think it happens because of this string in the >>>> gen_pool_alloc_algo(): >>>> >>>> addr = chunk->start_addr + ((unsigned long)start_bit << order); >>>> >>>> and the gen_pool_first_fit_align() implementation that doesn't take into >>>> account the "incorrect" chunk base alignment. >>> >>> gen_pool_first_fit_align() has no information about the chunk base >>> alignment. Hence, it can't take it into account. >>> >>> How do you request the alignment in your code? >>> >>> I agree with your analysis that gen_pool_first_fit_align() performs >>> alignment only with respect to the start of the chunk not the memory >>> address that gen_pool_alloc_algo() returns. I guess a solution would >>> be to only add chunks that satisfy all your alignment requirements. In >>> your case, you must only add chunks that are 16MB aligned. >>> I am unsure whether this is by design, but I believe it's the way that >>> the code currently works. >>> >> >> Daniel, >> >> I think the better solution is to use bitmap_find_next_zero_area_off() >> that receives the bit offset (CMA allocator uses it to solve the same >> issue). Of course, we need to pass the chunk base address to the >> gen_pool_first_fit_align(). >> >> What do you think? > > Yeah, I guess you could extend genpool_algo_t to include the > information you need i.e. the offset and then provide a modified > version of gen_pool_first_fit_align() that does take your offset into > account. I wouldn't change gen_pool_first_fit_align(), though, because > existing users might depend on the current behavior. > I think that the "fixed" version of gen_pool_first_fit_align() is less restrictive with respect to chunk base address - it will work correctly with arbitrary aligned chunks. Thanks, Alexey