0

I want to know HOW memory allocated for BIO gets free specific to RHEL 7.

I think, in RHEL 7 , bio->destructor field is removed from the bio structure.

So, how exactly the memory will be freed?

Thanks in Advance.!

amitam
  • 342
  • 2
  • 13

1 Answers1

1

The best way to know, why particular change is made in linux kernel, is to search through git journals in the Linux kernel sources:

git log -S bio_destructor_t -- include/linux/blk_types.h

This found that commit:

block: Kill bi_destructor

Now that we've got generic code for freeing bios allocated from bio pools, this isn't needed anymore.

This patch also makes bio_free() static, since without bi_destructor there should be no need for it to be called anywhere else.

See implementation of bio_free function for know about freeing memory in bio.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I still dont get why removing destructor has worked for freeing bio structures. Please confirm my following understanding--> The bi_pool field has been used as crieteria for calling the destructor before, right? bio_put has been added to free the bio memory. bio_put in turn will be calling kfree, which is used to free the memory got allocated by kmalloc. If you can, please provide me a link where it explains how the bio will be freed? rather, how removing destructor would still work for freeing bio's. – amitam Sep 09 '15 at 05:07
  • `bio_free` checks `bi_pool` field of bio. If it is set, this pool is used for free bio using `mempool_free`. Otherwise, simple `kfree` is used. I found this just from the implementation of `bio_kfree`. Did you try check that implementation? – Tsyvarev Sep 09 '15 at 06:38
  • While destructor was present, count was checked as well as bi_pool and accordingly bi_destructor would be called. But now what have question -> to free bio's we need to do bio_put from our side, to free the memory. Previously automatically destructor would be called to free the memory. Now do we need to explicitly mention call for bio_put in code of device driver? – amitam Sep 09 '15 at 06:45
  • From the point of device driver nothing has been changed: if you called `bio_put` before the patch, you still need to do that after the patch. – Tsyvarev Sep 09 '15 at 07:13
  • So, now what i am facing is a memory leak with RHEL7 but not with RHEL6 . In RHEL6 , we use destructor, and it will automatically get called, but what about RHEL7. Hope you are getting my question, as to what should be changed to perform my driver even in RHEL7.. – amitam Sep 09 '15 at 10:01
  • Oh, know I undestand: you **manually** allocate memory for bio or its components and want to free that memory. It is very difficult to advice something in code porting without veiwing code in question. Edit your question post, and add the code into it. (It is sufficient to post only bio-related code, which shows the problem). – Tsyvarev Sep 09 '15 at 10:41
  • Ok..But do you have any reference links, where i get to know how memory is freed in RHEL7? OR what are the changes related to freeing bio in RHEL7? something which has Explanation of full life cycle of bio in RHEL7? – amitam Sep 09 '15 at 12:34
  • I don't know about such reference links. – Tsyvarev Sep 09 '15 at 12:52